Class: ClaudeMemory::Store::PromptJourneyQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_memory/store/prompt_journey_query.rb

Overview

Cross-store query for the dashboard’s Prompt Journey panel. OTel events live in the global DB (writes hit the receiver, which is process-wide); activity_events with a back-tagged prompt_id can live in either store (hooks fire per-project, so hook_ingest / hook_context rows land in the project DB, while global may carry cross-project events). The query reads from all available stores and orders the merged stream by occurred_at.

Accepts either a single store (legacy callers) or a StoreManager. Returns plain row hashes shaped uniformly so the panel renders both sources without branching.

Instance Method Summary collapse

Constructor Details

#initialize(store_or_manager) ⇒ PromptJourneyQuery

Returns a new instance of PromptJourneyQuery.



17
18
19
20
21
22
23
24
# File 'lib/claude_memory/store/prompt_journey_query.rb', line 17

def initialize(store_or_manager)
  @stores = if store_or_manager.respond_to?(:project_store) || store_or_manager.respond_to?(:global_store)
    [store_or_manager.respond_to?(:project_store) ? store_or_manager.project_store : nil,
      store_or_manager.respond_to?(:global_store) ? store_or_manager.global_store : nil].compact
  else
    [store_or_manager].compact
  end
end

Instance Method Details

#fetch(prompt_id) ⇒ Array<Hash>

Returns rows ordered by occurred_at ascending.

Parameters:

  • prompt_id (String)

    OTel prompt.id UUID

Returns:

  • (Array<Hash>)

    rows ordered by occurred_at ascending



28
29
30
31
32
33
34
35
# File 'lib/claude_memory/store/prompt_journey_query.rb', line 28

def fetch(prompt_id)
  return [] if prompt_id.nil? || prompt_id.empty?

  rows = @stores.flat_map { |store|
    otel_rows(store, prompt_id) + activity_rows(store, prompt_id)
  }
  rows.sort_by { |r| r[:occurred_at].to_s }
end