Refactor settings management to use SettingsDefaultsManager
- Introduced SettingsDefaultsManager to centralize default settings and loading logic. - Updated context-generator, SDKAgent, SettingsRoutes, and worker-utils to utilize the new manager for loading settings. - Removed redundant code for reading settings from files and environment variables. - Ensured fallback to default values when settings file is missing or invalid.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
import{stdin as d}from"process";import w from"path";import{homedir as D}from"os";import{existsSync as E,readFileSync as x}from"fs";import{join as e,dirname as S,basename as O}from"path";import{homedir as g}from"os";import{fileURLToPath as y}from"url";function k(){return typeof __dirname<"u"?__dirname:S(y(import.meta.url))}var b=k(),r=process.env.CLAUDE_MEM_DATA_DIR||e(g(),".claude-mem"),u=process.env.CLAUDE_CONFIG_DIR||e(g(),".claude"),U=e(r,"archives"),j=e(r,"logs"),M=e(r,"trash"),N=e(r,"backups"),H=e(r,"settings.json"),W=e(r,"claude-mem.db"),F=e(r,"vector-db"),G=e(u,"settings.json"),K=e(u,"commands"),B=e(u,"CLAUDE.md");function f(){try{let t=w.join(D(),".claude-mem","settings.json");if(E(t)){let o=JSON.parse(x(t,"utf-8")),n=parseInt(o.env?.CLAUDE_MEM_WORKER_PORT,10);if(!isNaN(n))return n}}catch{}return parseInt(process.env.CLAUDE_MEM_WORKER_PORT||"37777",10)}import{appendFileSync as R}from"fs";import{homedir as T}from"os";import{join as A}from"path";var P=A(T(),".claude-mem","silent.log");function i(t,o,n=""){let a=new Date().toISOString(),p=((new Error().stack||"").split(`
|
||||
`)[2]||"").match(/at\s+(?:.*\s+)?\(?([^:]+):(\d+):(\d+)\)?/),h=p?`${p[1].split("/").pop()}:${p[2]}`:"unknown",c=`[${a}] [${h}] ${t}`;if(o!==void 0)try{c+=` ${JSON.stringify(o)}`}catch(m){c+=` [stringify error: ${m}]`}c+=`
|
||||
`;try{R(P,c)}catch(m){console.error("[silent-debug] Failed to write to log:",m)}return n}async function _(t){i("[cleanup-hook] Hook fired",{session_id:t?.session_id,cwd:t?.cwd,reason:t?.reason}),t||(console.log("No input provided - this script is designed to run as a Claude Code SessionEnd hook"),console.log(`
|
||||
Expected input format:`),console.log(JSON.stringify({session_id:"string",cwd:"string",transcript_path:"string",hook_event_name:"SessionEnd",reason:"exit"},null,2)),process.exit(0));let{session_id:o,reason:n}=t,a=f();try{let s=await fetch(`http://127.0.0.1:${a}/api/sessions/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({claudeSessionId:o,reason:n}),signal:AbortSignal.timeout(2e3)});if(s.ok){let l=await s.json();i("[cleanup-hook] Session cleanup completed",l)}else i("[cleanup-hook] Session not found or already cleaned up")}catch(s){i("[cleanup-hook] Worker not reachable (non-critical)",{error:s.message})}console.log('{"continue": true, "suppressOutput": true}'),process.exit(0)}if(d.isTTY)_(void 0);else{let t="";d.on("data",o=>t+=o),d.on("end",async()=>{let o=t?JSON.parse(t):void 0;await _(o)})}
|
||||
import{stdin as S}from"process";import h from"path";import{homedir as y}from"os";import{join as o,dirname as C,basename as v}from"path";import{homedir as g}from"os";import{fileURLToPath as D}from"url";function M(){return typeof __dirname<"u"?__dirname:C(D(import.meta.url))}var H=M(),s=process.env.CLAUDE_MEM_DATA_DIR||o(g(),".claude-mem"),l=process.env.CLAUDE_CONFIG_DIR||o(g(),".claude"),X=o(s,"archives"),B=o(s,"logs"),V=o(s,"trash"),$=o(s,"backups"),j=o(s,"settings.json"),G=o(s,"claude-mem.db"),K=o(s,"vector-db"),Y=o(l,"settings.json"),J=o(l,"commands"),q=o(l,"CLAUDE.md");import{readFileSync as R,existsSync as U}from"fs";var N=["bugfix","feature","refactor","discovery","decision","change"],L=["how-it-works","why-it-exists","what-changed","problem-solution","gotcha","pattern","trade-off"];var m=N.join(","),d=L.join(",");var p=class{static DEFAULTS={CLAUDE_MEM_MODEL:"claude-haiku-4-5",CLAUDE_MEM_CONTEXT_OBSERVATIONS:"50",CLAUDE_MEM_WORKER_PORT:"37777",CLAUDE_MEM_CONTEXT_SHOW_READ_TOKENS:"true",CLAUDE_MEM_CONTEXT_SHOW_WORK_TOKENS:"true",CLAUDE_MEM_CONTEXT_SHOW_SAVINGS_AMOUNT:"true",CLAUDE_MEM_CONTEXT_SHOW_SAVINGS_PERCENT:"true",CLAUDE_MEM_CONTEXT_OBSERVATION_TYPES:m,CLAUDE_MEM_CONTEXT_OBSERVATION_CONCEPTS:d,CLAUDE_MEM_CONTEXT_FULL_COUNT:"5",CLAUDE_MEM_CONTEXT_FULL_FIELD:"narrative",CLAUDE_MEM_CONTEXT_SESSION_COUNT:"10",CLAUDE_MEM_CONTEXT_SHOW_LAST_SUMMARY:"true",CLAUDE_MEM_CONTEXT_SHOW_LAST_MESSAGE:"false"};static getAllDefaults(){return{...this.DEFAULTS}}static get(t){return process.env[t]||this.DEFAULTS[t]}static getInt(t){let r=this.get(t);return parseInt(r,10)}static getBool(t){return this.get(t)==="true"}static loadFromFile(t){if(!U(t))return this.getAllDefaults();let r=R(t,"utf-8"),n=JSON.parse(r).env||{},i={...this.DEFAULTS};for(let _ of Object.keys(this.DEFAULTS))n[_]!==void 0&&(i[_]=n[_]);return i}};function O(){let e=h.join(y(),".claude-mem","settings.json"),t=p.loadFromFile(e);return parseInt(t.CLAUDE_MEM_WORKER_PORT,10)}import{appendFileSync as I}from"fs";import{homedir as x}from"os";import{join as P}from"path";var k=P(x(),".claude-mem","silent.log");function c(e,t,r=""){let a=new Date().toISOString(),u=((new Error().stack||"").split(`
|
||||
`)[2]||"").match(/at\s+(?:.*\s+)?\(?([^:]+):(\d+):(\d+)\)?/),A=u?`${u[1].split("/").pop()}:${u[2]}`:"unknown",E=`[${a}] [${A}] ${e}`;if(t!==void 0)try{E+=` ${JSON.stringify(t)}`}catch(T){E+=` [stringify error: ${T}]`}E+=`
|
||||
`;try{I(k,E)}catch(T){console.error("[silent-debug] Failed to write to log:",T)}return r}async function f(e){c("[cleanup-hook] Hook fired",{session_id:e?.session_id,cwd:e?.cwd,reason:e?.reason}),e||(console.log("No input provided - this script is designed to run as a Claude Code SessionEnd hook"),console.log(`
|
||||
Expected input format:`),console.log(JSON.stringify({session_id:"string",cwd:"string",transcript_path:"string",hook_event_name:"SessionEnd",reason:"exit"},null,2)),process.exit(0));let{session_id:t,reason:r}=e,a=O();try{let n=await fetch(`http://127.0.0.1:${a}/api/sessions/complete`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({claudeSessionId:t,reason:r}),signal:AbortSignal.timeout(2e3)});if(n.ok){let i=await n.json();c("[cleanup-hook] Session cleanup completed",i)}else c("[cleanup-hook] Session not found or already cleaned up")}catch(n){c("[cleanup-hook] Worker not reachable (non-critical)",{error:n.message})}console.log('{"continue": true, "suppressOutput": true}'),process.exit(0)}if(S.isTTY)f(void 0);else{let e="";S.on("data",t=>e+=t),S.on("end",async()=>{let t=e?JSON.parse(e):void 0;await f(t)})}
|
||||
|
||||
Reference in New Issue
Block a user