83b4806718
- Updated logging in `search-server.ts` to use `silentDebug` for non-critical messages, reducing console noise. - Added a health check endpoint in `worker-service.ts` to improve service monitoring. - Modified the worker service startup process to start the HTTP server immediately and perform slow initialization in the background. - Refactored database initialization in `Database.ts` to use the correct `Database` class. - Implemented a port availability check in `context-hook.ts` to ensure the worker service is ready before making requests.
3 lines
1.8 KiB
JavaScript
Executable File
3 lines
1.8 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
import D from"path";import{stdin as c}from"process";import{execSync as l}from"child_process";import w from"path";import{homedir as h}from"os";import{existsSync as R,readFileSync as x}from"fs";import{join as e,dirname as f,basename as T}from"path";import{homedir as p}from"os";import{fileURLToPath as g}from"url";function _(){return typeof __dirname<"u"?__dirname:f(g(import.meta.url))}var v=_(),n=process.env.CLAUDE_MEM_DATA_DIR||e(p(),".claude-mem"),i=process.env.CLAUDE_CONFIG_DIR||e(p(),".claude"),C=e(n,"archives"),b=e(n,"logs"),O=e(n,"trash"),U=e(n,"backups"),j=e(n,"settings.json"),M=e(n,"claude-mem.db"),W=e(n,"vector-db"),H=e(i,"settings.json"),L=e(i,"commands"),N=e(i,"CLAUDE.md");function m(){try{let t=w.join(h(),".claude-mem","settings.json");if(R(t)){let r=JSON.parse(x(t,"utf-8")),o=parseInt(r.env?.CLAUDE_MEM_WORKER_PORT,10);if(!isNaN(o))return o}}catch{}return parseInt(process.env.CLAUDE_MEM_WORKER_PORT||"37777",10)}async function S(t,r=1e4){let o=Date.now(),s=100;for(;Date.now()-o<r;)try{return l(`curl -s -f -m 1 "http://localhost:${t}/api/health" > /dev/null 2>&1`,{timeout:1e3}),!0}catch{await new Promise(a=>setTimeout(a,s))}return!1}async function u(t){let r=t?.cwd??process.cwd(),o=r?D.basename(r):"unknown-project",s=m();if(!await S(s))throw new Error(`Worker service not available on port ${s} after 10s. Try: npm run worker:restart`);let d=`http://localhost:${s}/api/context/inject?project=${encodeURIComponent(o)}`;return l(`curl -s "${d}"`,{encoding:"utf-8",timeout:5e3}).trim()}var E=process.argv.includes("--colors");if(c.isTTY||E)u(void 0).then(t=>{console.log(t),process.exit(0)});else{let t="";c.on("data",r=>t+=r),c.on("end",async()=>{let r=t.trim()?JSON.parse(t):void 0,o=await u(r);console.log(JSON.stringify({hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:o}})),process.exit(0)})}
|