Class: ClaudeMemory::Configuration
- Inherits:
-
Object
- Object
- ClaudeMemory::Configuration
- Defined in:
- lib/claude_memory/configuration.rb
Overview
Centralized configuration and ENV access Provides consistent access to paths and environment variables
Constant Summary collapse
- DEFAULT_STALE_DAYS =
Default staleness threshold (in days) for #35 access-based staleness. Active facts whose last_recalled_at is older than this — or never set, for facts created earlier than the same window — are flagged as candidates for review. Override via CLAUDE_MEMORY_STALE_DAYS.
14- DEFAULT_INJECTION_STALE_DAYS =
Threshold (in days) for the context-injection staleness marker. A single-value fact older than this and not recalled within it gets a “verify before relying” annotation when injected at SessionStart. Deliberately much longer than DEFAULT_STALE_DAYS (the dashboard’s review-candidate window) — the injection marker should fire only on facts old enough to be genuinely risky, not merely unused for a couple weeks. Override via CLAUDE_MEMORY_INJECTION_STALE_DAYS.
180
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
-
#claude_config_dir ⇒ String
Claude config directory (default: ~/.claude).
-
#global_db_path ⇒ String
Path to global memory database.
-
#home_dir ⇒ String
User home directory.
-
#initialize(env = ENV) ⇒ Configuration
constructor
A new instance of Configuration.
-
#injection_stale_days ⇒ Integer
Injection staleness threshold in days.
-
#otel_traces_enabled? ⇒ Boolean
Whether OTel trace ingestion is opted in.
-
#project_db_path(project_path = nil) ⇒ String
Path to project memory database.
-
#project_dir ⇒ String
Project root directory (resolves git worktrees).
-
#session_id ⇒ String?
Current Claude session ID from CLAUDE_SESSION_ID.
-
#settings_env ⇒ Hash
Read the env block from .claude/settings.json (project scope) so callers can inspect what Claude Code sees at session start.
-
#settings_json_path ⇒ String?
Path to the project-scoped settings.json.
-
#stale_days ⇒ Integer
Staleness threshold in days.
-
#transcript_path ⇒ String?
Path to current transcript from CLAUDE_TRANSCRIPT_PATH.
Constructor Details
#initialize(env = ENV) ⇒ Configuration
Returns a new instance of Configuration.
13 14 15 |
# File 'lib/claude_memory/configuration.rb', line 13 def initialize(env = ENV) @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
10 11 12 |
# File 'lib/claude_memory/configuration.rb', line 10 def env @env end |
Instance Method Details
#claude_config_dir ⇒ String
Returns Claude config directory (default: ~/.claude).
28 29 30 |
# File 'lib/claude_memory/configuration.rb', line 28 def claude_config_dir env["CLAUDE_CONFIG_DIR"] || File.join(home_dir, ".claude") end |
#global_db_path ⇒ String
Returns path to global memory database.
33 34 35 |
# File 'lib/claude_memory/configuration.rb', line 33 def global_db_path File.join(claude_config_dir, "memory.sqlite3") end |
#home_dir ⇒ String
Returns user home directory.
18 19 20 |
# File 'lib/claude_memory/configuration.rb', line 18 def home_dir env["HOME"] || File.("~") end |
#injection_stale_days ⇒ Integer
Returns injection staleness threshold in days.
80 81 82 83 84 85 86 87 |
# File 'lib/claude_memory/configuration.rb', line 80 def injection_stale_days raw = env["CLAUDE_MEMORY_INJECTION_STALE_DAYS"] return DEFAULT_INJECTION_STALE_DAYS if raw.nil? || raw.empty? parsed = Integer(raw, 10) (parsed > 0) ? parsed : DEFAULT_INJECTION_STALE_DAYS rescue ArgumentError DEFAULT_INJECTION_STALE_DAYS end |
#otel_traces_enabled? ⇒ Boolean
Whether OTel trace ingestion is opted in. Reads OTEL_TRACES_EXPORTER from .claude/settings.json’s env block. Traces are off unless the value is present and non-empty and not “none”. Set by ‘claude-memory otel –enable-traces`.
95 96 97 98 99 100 |
# File 'lib/claude_memory/configuration.rb', line 95 def otel_traces_enabled? value = settings_env["OTEL_TRACES_EXPORTER"] return false if value.nil? stripped = value.to_s.strip !stripped.empty? && stripped != "none" end |
#project_db_path(project_path = nil) ⇒ String
Returns path to project memory database.
39 40 41 42 |
# File 'lib/claude_memory/configuration.rb', line 39 def project_db_path(project_path = nil) path = project_path || project_dir File.join(path, ".claude", "memory.sqlite3") end |
#project_dir ⇒ String
Returns project root directory (resolves git worktrees).
23 24 25 |
# File 'lib/claude_memory/configuration.rb', line 23 def project_dir env["CLAUDE_PROJECT_DIR"] || resolve_project_dir end |
#session_id ⇒ String?
Returns current Claude session ID from CLAUDE_SESSION_ID.
45 46 47 |
# File 'lib/claude_memory/configuration.rb', line 45 def session_id env["CLAUDE_SESSION_ID"] end |
#settings_env ⇒ Hash
Read the env block from .claude/settings.json (project scope) so callers can inspect what Claude Code sees at session start. Returns an empty hash when the file is missing or unparseable — matches the tolerant behavior of Claude Code’s settings loader.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/claude_memory/configuration.rb', line 108 def settings_env path = settings_json_path return {} unless path raw = File.read(path) parsed = JSON.parse(raw) env_block = parsed.is_a?(Hash) ? parsed["env"] : nil env_block.is_a?(Hash) ? env_block : {} rescue JSON::ParserError, Errno::ENOENT {} end |
#settings_json_path ⇒ String?
Path to the project-scoped settings.json. nil when no project_dir exists (e.g. running outside any directory).
123 124 125 126 127 |
# File 'lib/claude_memory/configuration.rb', line 123 def settings_json_path dir = project_dir return nil unless dir File.join(dir, ".claude", "settings.json") end |
#stale_days ⇒ Integer
Returns staleness threshold in days.
61 62 63 64 65 66 67 68 |
# File 'lib/claude_memory/configuration.rb', line 61 def stale_days raw = env["CLAUDE_MEMORY_STALE_DAYS"] return DEFAULT_STALE_DAYS if raw.nil? || raw.empty? parsed = Integer(raw, 10) (parsed > 0) ? parsed : DEFAULT_STALE_DAYS rescue ArgumentError DEFAULT_STALE_DAYS end |
#transcript_path ⇒ String?
Returns path to current transcript from CLAUDE_TRANSCRIPT_PATH.
50 51 52 |
# File 'lib/claude_memory/configuration.rb', line 50 def transcript_path env["CLAUDE_TRANSCRIPT_PATH"] end |