Class: ClaudeMemory::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(env = ENV) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • env (Hash) (defaults to: ENV)

    environment variables (default: ENV)



13
14
15
# File 'lib/claude_memory/configuration.rb', line 13

def initialize(env = ENV)
  @env = env
end

Instance Attribute Details

#envObject (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_dirString

Returns Claude config directory (default: ~/.claude).

Returns:

  • (String)

    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_pathString

Returns path to global memory database.

Returns:

  • (String)

    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_dirString

Returns user home directory.

Returns:

  • (String)

    user home directory



18
19
20
# File 'lib/claude_memory/configuration.rb', line 18

def home_dir
  env["HOME"] || File.expand_path("~")
end

#injection_stale_daysInteger

Returns injection staleness threshold in days.

Returns:

  • (Integer)

    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`.

Returns:

  • (Boolean)


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.

Parameters:

  • project_path (String, nil) (defaults to: nil)

    override project root (defaults to project_dir)

Returns:

  • (String)

    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_dirString

Returns project root directory (resolves git worktrees).

Returns:

  • (String)

    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_idString?

Returns current Claude session ID from CLAUDE_SESSION_ID.

Returns:

  • (String, nil)

    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_envHash

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.

Returns:

  • (Hash)


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_pathString?

Path to the project-scoped settings.json. nil when no project_dir exists (e.g. running outside any directory).

Returns:

  • (String, nil)


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_daysInteger

Returns staleness threshold in days.

Returns:

  • (Integer)

    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_pathString?

Returns path to current transcript from CLAUDE_TRANSCRIPT_PATH.

Returns:

  • (String, nil)

    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