keepmind 1.1.0 → 1.1.1
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/.codex-plugin/plugin.json +1 -1
- package/dist/npx-cli/index.js +252 -252
- package/package.json +19 -18
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/bun.lock +4 -4
- package/plugin/package.json +3 -3
- package/plugin/scripts/mcp-server.cjs +1 -1
- package/plugin/scripts/transcript-watcher.cjs +0 -0
- package/plugin/scripts/worker-service.cjs +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keepmind",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Memory compression system for Claude Code - persist context across sessions (node-only fork of claude-mem)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
|
@@ -105,23 +105,12 @@
|
|
|
105
105
|
},
|
|
106
106
|
"//dependencies-note": "Local-only fork: the cloud/SaaS layer (Postgres + BullMQ + better-auth) and the `claude-mem/sdk` export were removed, so pg/better-auth/@better-auth/api-key/bullmq/ioredis are gone. zod + @modelcontextprotocol/sdk survive the bundler as live `import`/`require` in a shipped artifact (the mcp-server bundles zod). @huggingface/transformers + sqlite-vec power the in-process vector search (Phase 2, replacing the chroma-mcp/uvx subprocess) and are intentionally EXTERNALIZED from the worker bundle — transformers pulls onnxruntime-node (.node) and sqlite-vec loads a per-platform .dll/.so via getLoadablePath(), neither of which can be esbuild-inlined; they resolve from node_modules (and the generated plugin/package.json) at runtime. Everything else (express, react, react-dom, cors, dompurify, handlebars, @clack/prompts, ansi-to-html, glob, picocolors, shell-quote, yaml, zod-to-json-schema, @anthropic-ai/claude-agent-sdk) is esbuild-inlined into the worker/npx bundles, so it is a build-time devDependency.",
|
|
107
107
|
"overrides": {
|
|
108
|
-
"tmp": "^0.2.7"
|
|
108
|
+
"tmp": "^0.2.7",
|
|
109
|
+
"esbuild": "^0.28.0"
|
|
109
110
|
},
|
|
110
111
|
"devDependencies": {
|
|
111
|
-
"@anthropic-ai/claude-agent-sdk": "^0.3.
|
|
112
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.197",
|
|
112
113
|
"@clack/prompts": "^1.3.0",
|
|
113
|
-
"ansi-to-html": "^0.7.2",
|
|
114
|
-
"cors": "^2.8.6",
|
|
115
|
-
"dompurify": "^3.4.9",
|
|
116
|
-
"express": "^5.2.1",
|
|
117
|
-
"glob": "^13.0.6",
|
|
118
|
-
"handlebars": "^4.7.9",
|
|
119
|
-
"picocolors": "^1.1.1",
|
|
120
|
-
"react": "^19.2.6",
|
|
121
|
-
"react-dom": "^19.2.6",
|
|
122
|
-
"shell-quote": "^1.8.3",
|
|
123
|
-
"yaml": "^2.8.4",
|
|
124
|
-
"zod-to-json-schema": "^3.25.2",
|
|
125
114
|
"@derekstride/tree-sitter-sql": "^0.3.11",
|
|
126
115
|
"@tree-sitter-grammars/tree-sitter-lua": "^0.4.1",
|
|
127
116
|
"@tree-sitter-grammars/tree-sitter-markdown": "^0.3.2",
|
|
@@ -131,19 +120,29 @@
|
|
|
131
120
|
"@types/bun": "^1.3.13",
|
|
132
121
|
"@types/cors": "^2.8.19",
|
|
133
122
|
"@types/express": "^5.0.6",
|
|
134
|
-
"@types/node": "^
|
|
123
|
+
"@types/node": "^26.1.0",
|
|
135
124
|
"@types/react": "^19.2.17",
|
|
136
125
|
"@types/react-dom": "^19.2.3",
|
|
126
|
+
"ansi-to-html": "^0.7.2",
|
|
127
|
+
"cors": "^2.8.6",
|
|
128
|
+
"dompurify": "^3.4.9",
|
|
137
129
|
"esbuild": "^0.28.0",
|
|
130
|
+
"express": "^5.2.1",
|
|
131
|
+
"glob": "^13.0.6",
|
|
132
|
+
"handlebars": "^4.7.9",
|
|
138
133
|
"jimp": "^1.6.1",
|
|
139
134
|
"np": "^11.2.0",
|
|
140
135
|
"parse5": "^8.0.1",
|
|
136
|
+
"picocolors": "^1.1.1",
|
|
141
137
|
"postcss": "^8.5.14",
|
|
138
|
+
"react": "^19.2.6",
|
|
139
|
+
"react-dom": "^19.2.6",
|
|
142
140
|
"remark-mdx": "^3.1.1",
|
|
143
141
|
"remark-parse": "^11.0.0",
|
|
142
|
+
"shell-quote": "^1.9.0",
|
|
144
143
|
"tree-sitter-bash": "^0.25.1",
|
|
145
144
|
"tree-sitter-c": "^0.24.1",
|
|
146
|
-
"tree-sitter-cli": "^0.26.
|
|
145
|
+
"tree-sitter-cli": "^0.26.10",
|
|
147
146
|
"tree-sitter-cpp": "^0.23.4",
|
|
148
147
|
"tree-sitter-css": "^0.25.0",
|
|
149
148
|
"tree-sitter-elixir": "^0.3.5",
|
|
@@ -165,7 +164,9 @@
|
|
|
165
164
|
"tsx": "^4.21.0",
|
|
166
165
|
"typescript": "^6.0.3",
|
|
167
166
|
"unified": "^11.0.5",
|
|
168
|
-
"unist-util-visit": "^5.1.0"
|
|
167
|
+
"unist-util-visit": "^5.1.0",
|
|
168
|
+
"yaml": "^2.8.4",
|
|
169
|
+
"zod-to-json-schema": "^3.25.2"
|
|
169
170
|
},
|
|
170
171
|
"optionalDependencies": {
|
|
171
172
|
"tree-kill": "^1.2.2"
|
package/plugin/bun.lock
CHANGED
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
"@tree-sitter-grammars/tree-sitter-toml": "^0.7.0",
|
|
13
13
|
"@tree-sitter-grammars/tree-sitter-yaml": "^0.7.1",
|
|
14
14
|
"@tree-sitter-grammars/tree-sitter-zig": "^1.1.2",
|
|
15
|
-
"shell-quote": "^1.
|
|
15
|
+
"shell-quote": "^1.9.0",
|
|
16
16
|
"sqlite-vec": "^0.1.9",
|
|
17
17
|
"tree-sitter-bash": "^0.25.1",
|
|
18
18
|
"tree-sitter-c": "^0.24.1",
|
|
19
|
-
"tree-sitter-cli": "^0.26.
|
|
19
|
+
"tree-sitter-cli": "^0.26.10",
|
|
20
20
|
"tree-sitter-cpp": "^0.23.4",
|
|
21
21
|
"tree-sitter-css": "^0.25.0",
|
|
22
22
|
"tree-sitter-elixir": "^0.3.5",
|
|
@@ -202,7 +202,7 @@
|
|
|
202
202
|
|
|
203
203
|
"sharp": ["sharp@0.34.5", "", { "dependencies": { "@img/colour": "^1.0.0", "detect-libc": "^2.1.2", "semver": "^7.7.3" }, "optionalDependencies": { "@img/sharp-darwin-arm64": "0.34.5", "@img/sharp-darwin-x64": "0.34.5", "@img/sharp-libvips-darwin-arm64": "1.2.4", "@img/sharp-libvips-darwin-x64": "1.2.4", "@img/sharp-libvips-linux-arm": "1.2.4", "@img/sharp-libvips-linux-arm64": "1.2.4", "@img/sharp-libvips-linux-ppc64": "1.2.4", "@img/sharp-libvips-linux-riscv64": "1.2.4", "@img/sharp-libvips-linux-s390x": "1.2.4", "@img/sharp-libvips-linux-x64": "1.2.4", "@img/sharp-libvips-linuxmusl-arm64": "1.2.4", "@img/sharp-libvips-linuxmusl-x64": "1.2.4", "@img/sharp-linux-arm": "0.34.5", "@img/sharp-linux-arm64": "0.34.5", "@img/sharp-linux-ppc64": "0.34.5", "@img/sharp-linux-riscv64": "0.34.5", "@img/sharp-linux-s390x": "0.34.5", "@img/sharp-linux-x64": "0.34.5", "@img/sharp-linuxmusl-arm64": "0.34.5", "@img/sharp-linuxmusl-x64": "0.34.5", "@img/sharp-wasm32": "0.34.5", "@img/sharp-win32-arm64": "0.34.5", "@img/sharp-win32-ia32": "0.34.5", "@img/sharp-win32-x64": "0.34.5" } }, "sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg=="],
|
|
204
204
|
|
|
205
|
-
"shell-quote": ["shell-quote@1.
|
|
205
|
+
"shell-quote": ["shell-quote@1.9.0", "", {}, "sha512-Iov+JwFv/2HcTpcwNMKd8+IWNb8tboQJNQTkAY/LLVK7gGH9jy+LGkVqPxfekHl+yMmiqXszdGWXgkfml7hjqA=="],
|
|
206
206
|
|
|
207
207
|
"sprintf-js": ["sprintf-js@1.1.3", "", {}, "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA=="],
|
|
208
208
|
|
|
@@ -224,7 +224,7 @@
|
|
|
224
224
|
|
|
225
225
|
"tree-sitter-c": ["tree-sitter-c@0.24.1", "", { "dependencies": { "node-addon-api": "^8.3.1", "node-gyp-build": "^4.8.4" }, "peerDependencies": { "tree-sitter": "^0.22.4" }, "optionalPeers": ["tree-sitter"] }, "sha512-lkYwWN3SRecpvaeqmFKkuPNR3ZbtnvHU+4XAEEkJdrp3JfSp2pBrhXOtvfsENUneye76g889Y0ddF2DM0gEDpA=="],
|
|
226
226
|
|
|
227
|
-
"tree-sitter-cli": ["tree-sitter-cli@0.26.
|
|
227
|
+
"tree-sitter-cli": ["tree-sitter-cli@0.26.10", "", { "bin": { "tree-sitter": "cli.js" } }, "sha512-RTse32x5YWOrEtH7wos8ODt3yyB7SKgmGN70jC7R+WcnDA64vrpYU98+LnwrwdXMlxgr0LGQdezZz85DN8Wv0w=="],
|
|
228
228
|
|
|
229
229
|
"tree-sitter-cpp": ["tree-sitter-cpp@0.23.4", "", { "dependencies": { "node-addon-api": "^8.2.1", "node-gyp-build": "^4.8.2", "tree-sitter-c": "^0.23.1" }, "peerDependencies": { "tree-sitter": "^0.21.1" }, "optionalPeers": ["tree-sitter"] }, "sha512-qR5qUDyhZ5jJ6V8/umiBxokRbe89bCGmcq/dk94wI4kN86qfdV8k0GHIUEKaqWgcu42wKal5E97LKpLeVW8sKw=="],
|
|
230
230
|
|
package/plugin/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "keepmind-plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Runtime dependencies for keepmind bundled hooks",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"zod": "^4.4.3",
|
|
9
9
|
"@huggingface/transformers": "^4.2.0",
|
|
10
10
|
"sqlite-vec": "^0.1.9",
|
|
11
|
-
"tree-sitter-cli": "^0.26.
|
|
11
|
+
"tree-sitter-cli": "^0.26.10",
|
|
12
12
|
"tree-sitter-c": "^0.24.1",
|
|
13
13
|
"tree-sitter-cpp": "^0.23.4",
|
|
14
14
|
"tree-sitter-go": "^0.25.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@tree-sitter-grammars/tree-sitter-yaml": "^0.7.1",
|
|
34
34
|
"@derekstride/tree-sitter-sql": "^0.3.11",
|
|
35
35
|
"@tree-sitter-grammars/tree-sitter-markdown": "^0.3.2",
|
|
36
|
-
"shell-quote": "^1.
|
|
36
|
+
"shell-quote": "^1.9.0"
|
|
37
37
|
},
|
|
38
38
|
"overrides": {
|
|
39
39
|
"tree-sitter": "^0.25.0"
|
|
@@ -220,7 +220,7 @@ ${m}`}let c=i.lineStart;for(let l=i.lineStart-1;l>=0;l--){let d=a[l].trim();if(d
|
|
|
220
220
|
${u}`}var W_=new Set([".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".pyw",".go",".rs",".rb",".java",".cs",".cpp",".cc",".cxx",".c",".h",".hpp",".hh",".swift",".kt",".kts",".php",".vue",".svelte",".ex",".exs",".lua",".scala",".sc",".sh",".bash",".zsh",".hs",".zig",".css",".scss",".toml",".yml",".yaml",".sql",".md",".mdx"]),GP=new Set(["node_modules",".git","dist","build",".next","__pycache__",".venv","venv","env",".env","target","vendor",".cache",".turbo","coverage",".nyc_output",".claude",".smart-file-read"]),KP=512*1024;async function*V_(t,e,r=20,n){if(r<=0)return;let o;try{o=await(0,qr.readdir)(t,{withFileTypes:!0})}catch(s){y.debug("WORKER",`walkDir: failed to read directory ${t}`,void 0,s instanceof Error?s:void 0);return}for(let s of o){if(s.name.startsWith(".")&&s.name!=="."||GP.has(s.name))continue;let i=(0,ro.join)(t,s.name);if(s.isDirectory())yield*V_(i,e,r-1,n);else if(s.isFile()){let a=s.name.slice(s.name.lastIndexOf("."));(W_.has(a)||n&&n.has(a))&&(yield i)}}}async function JP(t){try{let e=await(0,qr.stat)(t);if(e.size>KP||e.size===0)return null;let r=await(0,qr.readFile)(t,"utf-8");return r.slice(0,1e3).includes("\0")?null:r}catch(e){return y.debug("WORKER",`safeReadFile: failed to read ${t}`,void 0,e instanceof Error?e:void 0),null}}async function G_(t,e,r={}){let n=r.maxResults||20,o=e.toLowerCase(),s=o.split(/[\s_\-./]+/).filter(w=>w.length>0),i=r.projectRoot||t,a=to(i),c=new Set;for(let w of Object.values(a.grammars))for(let v of w.extensions)W_.has(v)||c.add(v);let u=[];for await(let w of V_(t,t,20,c.size>0?c:void 0)){if(r.filePattern&&!(0,ro.relative)(t,w).toLowerCase().includes(r.filePattern.toLowerCase()))continue;let v=await JP(w);v&&u.push({absolutePath:w,relativePath:(0,ro.relative)(t,w),content:v})}let l=Z_(u,i),d=[],p=[],f=0;for(let[w,v]of l){f+=BP(v);let x=Ws(w.toLowerCase(),s)>0,ve=[],ke=(qt,sr)=>{for(let ce of qt){let Et=0,Je="",Zr=Ws(ce.name.toLowerCase(),s);Zr>0&&(Et+=Zr*3,Je="name match"),ce.signature.toLowerCase().includes(o)&&(Et+=2,Je=Je?`${Je} + signature`:"signature match"),ce.jsdoc&&ce.jsdoc.toLowerCase().includes(o)&&(Et+=1,Je=Je?`${Je} + jsdoc`:"jsdoc match"),Et>0&&(x=!0,ve.push({filePath:w,symbolName:sr?`${sr}.${ce.name}`:ce.name,kind:ce.kind,signature:ce.signature,jsdoc:ce.jsdoc,lineStart:ce.lineStart,lineEnd:ce.lineEnd,matchReason:Je})),ce.children&&ke(ce.children,ce.name)}};ke(v.symbols),x&&(d.push(v),p.push(...ve))}p.sort((w,v)=>{let $=Ws(w.symbolName.toLowerCase(),s);return Ws(v.symbolName.toLowerCase(),s)-$});let m=p.slice(0,n),_=new Set(m.map(w=>w.filePath)),S=d.filter(w=>_.has(w.filePath)).slice(0,n),b=S.reduce((w,v)=>w+v.foldedTokenEstimate,0);return{foldedFiles:S,matchingSymbols:m,totalFilesScanned:u.length,totalSymbolsFound:f,tokenEstimate:b}}function Ws(t,e){let r=0;for(let n of e)if(t===n)r+=10;else if(t.includes(n))r+=5;else{let o=0,s=0;for(let i of n){let a=t.indexOf(i,o);a!==-1&&(s++,o=a+1)}s===n.length&&(r+=1)}return r}function BP(t){let e=t.symbols.length;for(let r of t.symbols)r.children&&(e+=r.children.length);return e}function K_(t,e){let r=[];if(r.push(`\u{1F50D} Smart Search: "${e}"`),r.push(` Scanned ${t.totalFilesScanned} files, found ${t.totalSymbolsFound} symbols`),r.push(` ${t.matchingSymbols.length} matches across ${t.foldedFiles.length} files (~${t.tokenEstimate} tokens for folded view)`),r.push(""),t.matchingSymbols.length===0)return r.push(" No matching symbols found."),r.join(`
|
|
221
221
|
`);r.push("\u2500\u2500 Matching Symbols \u2500\u2500"),r.push("");for(let n of t.matchingSymbols){if(r.push(` ${n.kind} ${n.symbolName} (${n.filePath}:${n.lineStart+1})`),r.push(` ${n.signature}`),n.jsdoc){let o=n.jsdoc.split(`
|
|
222
222
|
`).find(s=>s.replace(/^[\s*/]+/,"").trim().length>0);o&&r.push(` \u{1F4AC} ${o.replace(/^[\s*/]+/,"").trim()}`)}r.push("")}r.push("\u2500\u2500 Folded File Views \u2500\u2500"),r.push("");for(let n of t.foldedFiles)r.push(Ur(n)),r.push("");return r.push("\u2500\u2500 Actions \u2500\u2500"),r.push(" To see full implementation: use smart_unfold with file path and symbol name"),r.join(`
|
|
223
|
-
`)}var Du=require("node:fs/promises"),Ks=require("node:fs"),rt=require("node:path"),ny=require("node:os"),oy=require("node:url");var J_="claude";function YP(t){return t.trim().toLowerCase().replace(/\s+/g,"-")}function Vs(t){if(!t)return J_;let e=YP(t);return e?e==="transcript"||e.includes("codex")?"codex":e.includes("cursor")?"cursor":e.includes("claude")?"claude":e:J_}var XP=bt(ue.API_REQUEST),Ke=class extends Error{kind;status;cause;constructor(e,r,n={}){super(r),this.name="ServerClientError",this.kind=e,this.status=n.status??null,this.cause=n.cause}isFallbackEligible(){return this.kind==="transport"||this.kind==="timeout"||this.kind==="missing_api_key"||this.kind==="http_error"&&(this.status!==null&&this.status>=500||this.status===429)}},Gs=class{baseUrl;apiKey;timeoutMs;constructor(e){this.baseUrl=QP(e.serverBaseUrl),this.apiKey=e.apiKey,this.timeoutMs=e.timeoutMs??XP}async startSession(e){let r=this.buildStartSessionPayload(e);return this.request("POST","/v1/sessions/start",r)}async recordEvent(e){let r=this.buildEventPayload(e),n=e.generate===!1?"/v1/events?generate=false":"/v1/events";return this.request("POST",n,r)}async endSession(e){if(!e.sessionId)throw new Ke("invalid_response","sessionId is required for endSession");return this.request("POST",`/v1/sessions/${encodeURIComponent(e.sessionId)}/end`,{})}async addObservation(e){return this.request("POST","/v1/memories",this.buildAddObservationPayload(e))}async searchObservations(e){return this.request("POST","/v1/search",this.buildSearchPayload(e))}async contextObservations(e){return this.request("POST","/v1/context",this.buildSearchPayload(e))}async getJobStatus(e){if(!e)throw new Ke("invalid_response","jobId is required for getJobStatus");return this.request("GET",`/v1/jobs/${encodeURIComponent(e)}`)}buildAddObservationPayload(e){let r=e.content,n=e.kind??"manual",o=typeof e.metadata?.title=="string"?e.metadata.title:void 0;return{projectId:e.projectId,kind:n,type:n,narrative:r,...o?{title:o}:{},...e.serverSessionId!==void 0?{serverSessionId:e.serverSessionId}:{},...e.metadata!==void 0?{metadata:e.metadata}:{}}}buildSearchPayload(e){return{projectId:e.projectId,query:e.query,...e.limit!==void 0?{limit:e.limit}:{},...e.platformSource!==void 0?{platformSource:Au(e.platformSource)}:{}}}buildStartSessionPayload(e){return{projectId:e.projectId,...e.externalSessionId!==void 0?{externalSessionId:e.externalSessionId}:{},...e.contentSessionId!==void 0?{contentSessionId:e.contentSessionId}:{},...e.agentId!==void 0?{agentId:e.agentId}:{},...e.agentType!==void 0?{agentType:e.agentType}:{},...e.platformSource!==void 0?{platformSource:Au(e.platformSource)}:{},...e.metadata!==void 0?{metadata:e.metadata}:{}}}buildEventPayload(e){return{projectId:e.projectId,sourceType:e.sourceType,eventType:e.eventType,occurredAtEpoch:e.occurredAtEpoch,...e.serverSessionId!==void 0?{serverSessionId:e.serverSessionId}:{},...e.contentSessionId!==void 0?{contentSessionId:e.contentSessionId}:{},...e.memorySessionId!==void 0?{memorySessionId:e.memorySessionId}:{},...e.platformSource!==void 0?{platformSource:Au(e.platformSource)}:{},...e.payload!==void 0?{payload:e.payload}:{}}}async request(e,r,n){if(!this.apiKey||!this.apiKey.trim())throw new Ke("missing_api_key","Server API key is not configured (CLAUDE_MEM_SERVER_API_KEY).");let o=`${this.baseUrl}${r}`,s={method:e,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}};n!==void 0&&(s.body=JSON.stringify(n));let i;try{i=await Eu(o,s,this.timeoutMs)}catch(c){let u=c instanceof Error?c.message:String(c),l=/timed out|timeout/i.test(u);throw new Ke(l?"timeout":"transport",`Server ${e} ${r} failed: ${u}`,{cause:c})}if(!i.ok){let c=await i.text().catch(()=>"");throw new Ke("http_error",`Server ${e} ${r} returned ${i.status}: ${eT(c,200)}`,{status:i.status})}let a=await i.text();if(!a||a.length===0)return{};try{return JSON.parse(a)}catch(c){throw new Ke("invalid_response",`Server ${e} ${r} returned non-JSON response`,{cause:c})}}};function B_(t){return t instanceof Ke}function QP(t){return t.replace(/\/+$/,"")}function Au(t){return typeof t=="string"?Vs(t):null}function eT(t,e){return t.length<=e?t:`${t.slice(0,e)}\u2026`}function Mu(){let e=(Ms().CLAUDE_MEM_RUNTIME??"worker").trim().toLowerCase();return e==="server"||e==="server-beta"?"server":"worker"}function Y_(){let t=Ms(),e=(...i)=>{for(let a of i){let c=(a??"").trim();if(c.length>0)return c}return""},r=e(t.CLAUDE_MEM_SERVER_URL,t.CLAUDE_MEM_SERVER_BETA_URL),n=e(t.CLAUDE_MEM_SERVER_API_KEY,t.CLAUDE_MEM_SERVER_BETA_API_KEY),o=e(t.CLAUDE_MEM_SERVER_PROJECT_ID,t.CLAUDE_MEM_SERVER_BETA_PROJECT_ID);if(!r)return y.warn("HOOK","[server-fallback] reason=missing_base_url"),null;if(!n)return y.warn("HOOK","[server-fallback] reason=missing_api_key"),null;if(!o)return y.warn("HOOK","[server-fallback] reason=missing_project_id"),null;let s={serverBaseUrl:r,apiKey:n};return{runtime:"server",client:new Gs(s),projectId:o,serverBaseUrl:r}}var yT={},tT="1.1.0";console.log=(...t)=>{y.error("CONSOLE","Intercepted console output (MCP protocol protection)",void 0,{args:t})};var sy=!1,iy=(()=>{if(typeof __dirname<"u")return __dirname;try{return(0,rt.dirname)((0,oy.fileURLToPath)(yT.url))}catch{return sy=!0,process.cwd()}})(),Nu=P_()??(0,rt.resolve)(iy,"worker-service.cjs");function rT(){sy&&((0,Ks.existsSync)(Nu)||y.error("SYSTEM","mcp-server: dirname resolution failed (both __dirname and import.meta.url are unavailable). Fell back to process.cwd() and the resolved WORKER_SCRIPT_PATH does not exist. This is the actual problem \u2014 the worker bundle is fine, but mcp-server cannot locate it. Worker auto-start will fail until the dirname-resolution path is fixed.",{workerScriptPath:Nu,mcpServerDir:iy}))}var X_={search:"/api/search",timeline:"/api/timeline"};async function Cu(t,e){y.debug("SYSTEM","\u2192 Worker API",void 0,{endpoint:t,params:e});let r=new URLSearchParams;for(let[o,s]of Object.entries(e))s!=null&&r.append(o,String(s));let n=`${t}?${r}`;try{let o=await Xn(n);if(!o.ok){let i=await o.text();throw new Error(`Worker API error (${o.status}): ${i}`)}let s=await o.json();return y.debug("SYSTEM","\u2190 Worker API success",void 0,{endpoint:t}),s}catch(o){return y.error("SYSTEM","\u2190 Worker API error",{endpoint:t},o instanceof Error?o:new Error(String(o))),{content:[{type:"text",text:`Error calling Worker API: ${o instanceof Error?o.message:String(o)}`}],isError:!0}}}async function nT(t,e){y.debug("SYSTEM","\u2192 Worker API text",void 0,{endpoint:t,params:e});let r=new URLSearchParams;for(let[o,s]of Object.entries(e))s!=null&&r.append(o,String(s));let n=`${t}?${r}`;try{let o=await Xn(n);if(!o.ok){let i=await o.text();throw new Error(`Worker API error (${o.status}): ${i}`)}let s=await o.text();return y.debug("SYSTEM","\u2190 Worker API text success",void 0,{endpoint:t}),{content:[{type:"text",text:s}]}}catch(o){return y.error("SYSTEM","\u2190 Worker API text error",{endpoint:t},o instanceof Error?o:new Error(String(o))),{content:[{type:"text",text:`Error calling Worker API: ${o instanceof Error?o.message:String(o)}`}],isError:!0}}}async function oT(t,e){let r=await Xn(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok){let o=await r.text();throw new Error(`Worker API error (${r.status}): ${o}`)}let n=await r.json();return y.debug("HTTP","Worker API success (POST)",void 0,{endpoint:t}),{content:[{type:"text",text:JSON.stringify(n,null,2)}]}}async function or(t,e){y.debug("HTTP","Worker API request (POST)",void 0,{endpoint:t});try{return await oT(t,e)}catch(r){return y.error("HTTP","Worker API error (POST)",{endpoint:t},r instanceof Error?r:new Error(String(r))),{content:[{type:"text",text:`Error calling Worker API: ${r instanceof Error?r.message:String(r)}`}],isError:!0}}}async function sT(){try{return(await Xn("/api/health")).ok}catch(t){return y.debug("SYSTEM","Worker health check failed",{},t instanceof Error?t:new Error(String(t))),!1}}function iT(){if(Mu()!=="server")return null;let e=Y_();return e?{...e,available:!0}:{runtime:"server",available:!1,reason:"server runtime is selected but configuration is incomplete (missing url, api key, or project id)"}}function oo(t){return B_(t)?{content:[{type:"text",text:`Server error (${t.kind}${t.status?` ${t.status}`:""}): ${t.message}`}],isError:!0}:{content:[{type:"text",text:`Tool error: ${t instanceof Error?t.message:String(t)}`}],isError:!0}}function so(t){return{content:[{type:"text",text:JSON.stringify(t,null,2)}]}}function io(t){let e=iT();if(!e)throw new Ke("transport",`${t} requires CLAUDE_MEM_RUNTIME=server. Current runtime is "worker"; use the existing search/timeline/get_observations tools for worker-mode memory access.`);if(!e.available)throw new Ke("missing_api_key",`${t}: ${e.reason}`);return e}async function Q_(t){try{let e=io("observation_add");if(typeof t?.content!="string"||t.content.trim().length===0)throw new Error('observation_add: "content" is required');let n={projectId:t.projectId&&t.projectId.trim().length>0?t.projectId:e.projectId,content:t.content,...t.serverSessionId!==void 0?{serverSessionId:t.serverSessionId}:{},...t.kind!==void 0?{kind:t.kind}:{},...t.metadata!==void 0?{metadata:t.metadata}:{}},o=await e.client.addObservation(n);return so(o)}catch(e){return oo(e)}}function Bs(t){return typeof t=="string"?Vs(t):null}async function aT(t){try{let e=io("observation_record_event");if(typeof t?.eventType!="string"||t.eventType.trim().length===0)throw new Error('observation_record_event: "eventType" is required');let n={projectId:t.projectId&&t.projectId.trim().length>0?t.projectId:e.projectId,sourceType:t.sourceType??"api",eventType:t.eventType,occurredAtEpoch:typeof t.occurredAtEpoch=="number"?t.occurredAtEpoch:Date.now(),...t.serverSessionId!==void 0?{serverSessionId:t.serverSessionId}:{},...t.contentSessionId!==void 0?{contentSessionId:t.contentSessionId}:{},...t.memorySessionId!==void 0?{memorySessionId:t.memorySessionId}:{},...t.platformSource!==void 0?{platformSource:Bs(t.platformSource)}:{},...t.payload!==void 0?{payload:t.payload}:{},...t.generate!==void 0?{generate:t.generate}:{}},o=await e.client.recordEvent(n);return so(o)}catch(e){return oo(e)}}async function ey(t){try{let e=io("observation_search");if(typeof t?.query!="string"||t.query.trim().length===0)throw new Error('observation_search: "query" is required');let n={projectId:t.projectId&&t.projectId.trim().length>0?t.projectId:e.projectId,query:t.query,...t.limit!==void 0?{limit:t.limit}:{},...t.platformSource!==void 0?{platformSource:Bs(t.platformSource)}:{}},o=await e.client.searchObservations(n);return so(o)}catch(e){return oo(e)}}async function ty(t){try{let e=io("observation_context");if(typeof t?.query!="string"||t.query.trim().length===0)throw new Error('observation_context: "query" is required');let n={projectId:t.projectId&&t.projectId.trim().length>0?t.projectId:e.projectId,query:t.query,...t.limit!==void 0?{limit:t.limit}:{},...t.platformSource!==void 0?{platformSource:Bs(t.platformSource)}:{}},o=await e.client.contextObservations(n);return so(o)}catch(e){return oo(e)}}function cT(t){return Array.isArray(t.projects)?t.projects.map(e=>typeof e=="string"?e.trim():"").filter(Boolean):typeof t.projects=="string"?t.projects.split(",").map(e=>e.trim()).filter(Boolean):typeof t.project=="string"&&t.project.trim().length>0?[t.project.trim()]:[]}async function uT(t){let e=cT(t);return e.length===0?{content:[{type:"text",text:'session_start_context: "project" or "projects" is required'}],isError:!0}:nT("/api/context/inject",{projects:e.join(","),...t.platformSource!==void 0?{platformSource:Bs(t.platformSource)}:{},...t.full!==void 0?{full:t.full}:{},...t.colors!==void 0?{colors:t.colors}:{}})}async function lT(t){try{let e=io("observation_generation_status"),r=(t?.jobId??t?.job_id??"").trim();if(!r)throw new Error('observation_generation_status: "jobId" is required');let n=await e.client.getJobStatus(r);return so(n)}catch(e){return oo(e)}}async function dT(){if(await sT())return!0;y.warn("SYSTEM","Worker not available, attempting auto-start for MCP client"),rT();try{let t=xu(),e=await z_(t,Nu);return e==="dead"&&y.error("SYSTEM","Worker auto-start failed \u2014 MCP tools that require the worker (search, timeline, get_observations) will fail until the worker is running. Check earlier log lines for the specific failure reason (Bun not found, missing worker bundle, port conflict, etc.)."),e!=="dead"}catch(t){return y.error("SYSTEM","Worker auto-start threw \u2014 MCP tools that require the worker (search, timeline, get_observations) will fail until the worker is running.",void 0,t instanceof Error?t:new Error(String(t))),!1}}var ay=[{name:"__IMPORTANT",description:`3-LAYER WORKFLOW (ALWAYS FOLLOW):
|
|
223
|
+
`)}var Du=require("node:fs/promises"),Ks=require("node:fs"),rt=require("node:path"),ny=require("node:os"),oy=require("node:url");var J_="claude";function YP(t){return t.trim().toLowerCase().replace(/\s+/g,"-")}function Vs(t){if(!t)return J_;let e=YP(t);return e?e==="transcript"||e.includes("codex")?"codex":e.includes("cursor")?"cursor":e.includes("claude")?"claude":e:J_}var XP=bt(ue.API_REQUEST),Ke=class extends Error{kind;status;cause;constructor(e,r,n={}){super(r),this.name="ServerClientError",this.kind=e,this.status=n.status??null,this.cause=n.cause}isFallbackEligible(){return this.kind==="transport"||this.kind==="timeout"||this.kind==="missing_api_key"||this.kind==="http_error"&&(this.status!==null&&this.status>=500||this.status===429)}},Gs=class{baseUrl;apiKey;timeoutMs;constructor(e){this.baseUrl=QP(e.serverBaseUrl),this.apiKey=e.apiKey,this.timeoutMs=e.timeoutMs??XP}async startSession(e){let r=this.buildStartSessionPayload(e);return this.request("POST","/v1/sessions/start",r)}async recordEvent(e){let r=this.buildEventPayload(e),n=e.generate===!1?"/v1/events?generate=false":"/v1/events";return this.request("POST",n,r)}async endSession(e){if(!e.sessionId)throw new Ke("invalid_response","sessionId is required for endSession");return this.request("POST",`/v1/sessions/${encodeURIComponent(e.sessionId)}/end`,{})}async addObservation(e){return this.request("POST","/v1/memories",this.buildAddObservationPayload(e))}async searchObservations(e){return this.request("POST","/v1/search",this.buildSearchPayload(e))}async contextObservations(e){return this.request("POST","/v1/context",this.buildSearchPayload(e))}async getJobStatus(e){if(!e)throw new Ke("invalid_response","jobId is required for getJobStatus");return this.request("GET",`/v1/jobs/${encodeURIComponent(e)}`)}buildAddObservationPayload(e){let r=e.content,n=e.kind??"manual",o=typeof e.metadata?.title=="string"?e.metadata.title:void 0;return{projectId:e.projectId,kind:n,type:n,narrative:r,...o?{title:o}:{},...e.serverSessionId!==void 0?{serverSessionId:e.serverSessionId}:{},...e.metadata!==void 0?{metadata:e.metadata}:{}}}buildSearchPayload(e){return{projectId:e.projectId,query:e.query,...e.limit!==void 0?{limit:e.limit}:{},...e.platformSource!==void 0?{platformSource:Au(e.platformSource)}:{}}}buildStartSessionPayload(e){return{projectId:e.projectId,...e.externalSessionId!==void 0?{externalSessionId:e.externalSessionId}:{},...e.contentSessionId!==void 0?{contentSessionId:e.contentSessionId}:{},...e.agentId!==void 0?{agentId:e.agentId}:{},...e.agentType!==void 0?{agentType:e.agentType}:{},...e.platformSource!==void 0?{platformSource:Au(e.platformSource)}:{},...e.metadata!==void 0?{metadata:e.metadata}:{}}}buildEventPayload(e){return{projectId:e.projectId,sourceType:e.sourceType,eventType:e.eventType,occurredAtEpoch:e.occurredAtEpoch,...e.serverSessionId!==void 0?{serverSessionId:e.serverSessionId}:{},...e.contentSessionId!==void 0?{contentSessionId:e.contentSessionId}:{},...e.memorySessionId!==void 0?{memorySessionId:e.memorySessionId}:{},...e.platformSource!==void 0?{platformSource:Au(e.platformSource)}:{},...e.payload!==void 0?{payload:e.payload}:{}}}async request(e,r,n){if(!this.apiKey||!this.apiKey.trim())throw new Ke("missing_api_key","Server API key is not configured (CLAUDE_MEM_SERVER_API_KEY).");let o=`${this.baseUrl}${r}`,s={method:e,headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}};n!==void 0&&(s.body=JSON.stringify(n));let i;try{i=await Eu(o,s,this.timeoutMs)}catch(c){let u=c instanceof Error?c.message:String(c),l=/timed out|timeout/i.test(u);throw new Ke(l?"timeout":"transport",`Server ${e} ${r} failed: ${u}`,{cause:c})}if(!i.ok){let c=await i.text().catch(()=>"");throw new Ke("http_error",`Server ${e} ${r} returned ${i.status}: ${eT(c,200)}`,{status:i.status})}let a=await i.text();if(!a||a.length===0)return{};try{return JSON.parse(a)}catch(c){throw new Ke("invalid_response",`Server ${e} ${r} returned non-JSON response`,{cause:c})}}};function B_(t){return t instanceof Ke}function QP(t){return t.replace(/\/+$/,"")}function Au(t){return typeof t=="string"?Vs(t):null}function eT(t,e){return t.length<=e?t:`${t.slice(0,e)}\u2026`}function Mu(){let e=(Ms().CLAUDE_MEM_RUNTIME??"worker").trim().toLowerCase();return e==="server"||e==="server-beta"?"server":"worker"}function Y_(){let t=Ms(),e=(...i)=>{for(let a of i){let c=(a??"").trim();if(c.length>0)return c}return""},r=e(t.CLAUDE_MEM_SERVER_URL,t.CLAUDE_MEM_SERVER_BETA_URL),n=e(t.CLAUDE_MEM_SERVER_API_KEY,t.CLAUDE_MEM_SERVER_BETA_API_KEY),o=e(t.CLAUDE_MEM_SERVER_PROJECT_ID,t.CLAUDE_MEM_SERVER_BETA_PROJECT_ID);if(!r)return y.warn("HOOK","[server-fallback] reason=missing_base_url"),null;if(!n)return y.warn("HOOK","[server-fallback] reason=missing_api_key"),null;if(!o)return y.warn("HOOK","[server-fallback] reason=missing_project_id"),null;let s={serverBaseUrl:r,apiKey:n};return{runtime:"server",client:new Gs(s),projectId:o,serverBaseUrl:r}}var yT={},tT="1.1.1";console.log=(...t)=>{y.error("CONSOLE","Intercepted console output (MCP protocol protection)",void 0,{args:t})};var sy=!1,iy=(()=>{if(typeof __dirname<"u")return __dirname;try{return(0,rt.dirname)((0,oy.fileURLToPath)(yT.url))}catch{return sy=!0,process.cwd()}})(),Nu=P_()??(0,rt.resolve)(iy,"worker-service.cjs");function rT(){sy&&((0,Ks.existsSync)(Nu)||y.error("SYSTEM","mcp-server: dirname resolution failed (both __dirname and import.meta.url are unavailable). Fell back to process.cwd() and the resolved WORKER_SCRIPT_PATH does not exist. This is the actual problem \u2014 the worker bundle is fine, but mcp-server cannot locate it. Worker auto-start will fail until the dirname-resolution path is fixed.",{workerScriptPath:Nu,mcpServerDir:iy}))}var X_={search:"/api/search",timeline:"/api/timeline"};async function Cu(t,e){y.debug("SYSTEM","\u2192 Worker API",void 0,{endpoint:t,params:e});let r=new URLSearchParams;for(let[o,s]of Object.entries(e))s!=null&&r.append(o,String(s));let n=`${t}?${r}`;try{let o=await Xn(n);if(!o.ok){let i=await o.text();throw new Error(`Worker API error (${o.status}): ${i}`)}let s=await o.json();return y.debug("SYSTEM","\u2190 Worker API success",void 0,{endpoint:t}),s}catch(o){return y.error("SYSTEM","\u2190 Worker API error",{endpoint:t},o instanceof Error?o:new Error(String(o))),{content:[{type:"text",text:`Error calling Worker API: ${o instanceof Error?o.message:String(o)}`}],isError:!0}}}async function nT(t,e){y.debug("SYSTEM","\u2192 Worker API text",void 0,{endpoint:t,params:e});let r=new URLSearchParams;for(let[o,s]of Object.entries(e))s!=null&&r.append(o,String(s));let n=`${t}?${r}`;try{let o=await Xn(n);if(!o.ok){let i=await o.text();throw new Error(`Worker API error (${o.status}): ${i}`)}let s=await o.text();return y.debug("SYSTEM","\u2190 Worker API text success",void 0,{endpoint:t}),{content:[{type:"text",text:s}]}}catch(o){return y.error("SYSTEM","\u2190 Worker API text error",{endpoint:t},o instanceof Error?o:new Error(String(o))),{content:[{type:"text",text:`Error calling Worker API: ${o instanceof Error?o.message:String(o)}`}],isError:!0}}}async function oT(t,e){let r=await Xn(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok){let o=await r.text();throw new Error(`Worker API error (${r.status}): ${o}`)}let n=await r.json();return y.debug("HTTP","Worker API success (POST)",void 0,{endpoint:t}),{content:[{type:"text",text:JSON.stringify(n,null,2)}]}}async function or(t,e){y.debug("HTTP","Worker API request (POST)",void 0,{endpoint:t});try{return await oT(t,e)}catch(r){return y.error("HTTP","Worker API error (POST)",{endpoint:t},r instanceof Error?r:new Error(String(r))),{content:[{type:"text",text:`Error calling Worker API: ${r instanceof Error?r.message:String(r)}`}],isError:!0}}}async function sT(){try{return(await Xn("/api/health")).ok}catch(t){return y.debug("SYSTEM","Worker health check failed",{},t instanceof Error?t:new Error(String(t))),!1}}function iT(){if(Mu()!=="server")return null;let e=Y_();return e?{...e,available:!0}:{runtime:"server",available:!1,reason:"server runtime is selected but configuration is incomplete (missing url, api key, or project id)"}}function oo(t){return B_(t)?{content:[{type:"text",text:`Server error (${t.kind}${t.status?` ${t.status}`:""}): ${t.message}`}],isError:!0}:{content:[{type:"text",text:`Tool error: ${t instanceof Error?t.message:String(t)}`}],isError:!0}}function so(t){return{content:[{type:"text",text:JSON.stringify(t,null,2)}]}}function io(t){let e=iT();if(!e)throw new Ke("transport",`${t} requires CLAUDE_MEM_RUNTIME=server. Current runtime is "worker"; use the existing search/timeline/get_observations tools for worker-mode memory access.`);if(!e.available)throw new Ke("missing_api_key",`${t}: ${e.reason}`);return e}async function Q_(t){try{let e=io("observation_add");if(typeof t?.content!="string"||t.content.trim().length===0)throw new Error('observation_add: "content" is required');let n={projectId:t.projectId&&t.projectId.trim().length>0?t.projectId:e.projectId,content:t.content,...t.serverSessionId!==void 0?{serverSessionId:t.serverSessionId}:{},...t.kind!==void 0?{kind:t.kind}:{},...t.metadata!==void 0?{metadata:t.metadata}:{}},o=await e.client.addObservation(n);return so(o)}catch(e){return oo(e)}}function Bs(t){return typeof t=="string"?Vs(t):null}async function aT(t){try{let e=io("observation_record_event");if(typeof t?.eventType!="string"||t.eventType.trim().length===0)throw new Error('observation_record_event: "eventType" is required');let n={projectId:t.projectId&&t.projectId.trim().length>0?t.projectId:e.projectId,sourceType:t.sourceType??"api",eventType:t.eventType,occurredAtEpoch:typeof t.occurredAtEpoch=="number"?t.occurredAtEpoch:Date.now(),...t.serverSessionId!==void 0?{serverSessionId:t.serverSessionId}:{},...t.contentSessionId!==void 0?{contentSessionId:t.contentSessionId}:{},...t.memorySessionId!==void 0?{memorySessionId:t.memorySessionId}:{},...t.platformSource!==void 0?{platformSource:Bs(t.platformSource)}:{},...t.payload!==void 0?{payload:t.payload}:{},...t.generate!==void 0?{generate:t.generate}:{}},o=await e.client.recordEvent(n);return so(o)}catch(e){return oo(e)}}async function ey(t){try{let e=io("observation_search");if(typeof t?.query!="string"||t.query.trim().length===0)throw new Error('observation_search: "query" is required');let n={projectId:t.projectId&&t.projectId.trim().length>0?t.projectId:e.projectId,query:t.query,...t.limit!==void 0?{limit:t.limit}:{},...t.platformSource!==void 0?{platformSource:Bs(t.platformSource)}:{}},o=await e.client.searchObservations(n);return so(o)}catch(e){return oo(e)}}async function ty(t){try{let e=io("observation_context");if(typeof t?.query!="string"||t.query.trim().length===0)throw new Error('observation_context: "query" is required');let n={projectId:t.projectId&&t.projectId.trim().length>0?t.projectId:e.projectId,query:t.query,...t.limit!==void 0?{limit:t.limit}:{},...t.platformSource!==void 0?{platformSource:Bs(t.platformSource)}:{}},o=await e.client.contextObservations(n);return so(o)}catch(e){return oo(e)}}function cT(t){return Array.isArray(t.projects)?t.projects.map(e=>typeof e=="string"?e.trim():"").filter(Boolean):typeof t.projects=="string"?t.projects.split(",").map(e=>e.trim()).filter(Boolean):typeof t.project=="string"&&t.project.trim().length>0?[t.project.trim()]:[]}async function uT(t){let e=cT(t);return e.length===0?{content:[{type:"text",text:'session_start_context: "project" or "projects" is required'}],isError:!0}:nT("/api/context/inject",{projects:e.join(","),...t.platformSource!==void 0?{platformSource:Bs(t.platformSource)}:{},...t.full!==void 0?{full:t.full}:{},...t.colors!==void 0?{colors:t.colors}:{}})}async function lT(t){try{let e=io("observation_generation_status"),r=(t?.jobId??t?.job_id??"").trim();if(!r)throw new Error('observation_generation_status: "jobId" is required');let n=await e.client.getJobStatus(r);return so(n)}catch(e){return oo(e)}}async function dT(){if(await sT())return!0;y.warn("SYSTEM","Worker not available, attempting auto-start for MCP client"),rT();try{let t=xu(),e=await z_(t,Nu);return e==="dead"&&y.error("SYSTEM","Worker auto-start failed \u2014 MCP tools that require the worker (search, timeline, get_observations) will fail until the worker is running. Check earlier log lines for the specific failure reason (Bun not found, missing worker bundle, port conflict, etc.)."),e!=="dead"}catch(t){return y.error("SYSTEM","Worker auto-start threw \u2014 MCP tools that require the worker (search, timeline, get_observations) will fail until the worker is running.",void 0,t instanceof Error?t:new Error(String(t))),!1}}var ay=[{name:"__IMPORTANT",description:`3-LAYER WORKFLOW (ALWAYS FOLLOW):
|
|
224
224
|
1. search(query) \u2192 Get index with IDs (~50-100 tokens/result)
|
|
225
225
|
2. timeline(anchor=ID) \u2192 Get context around interesting results
|
|
226
226
|
3. get_observations([IDs]) \u2192 Fetch full details ONLY for filtered IDs
|
|
File without changes
|