Class: PromptObjects::Operations::Diagnostics

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt_objects/operations/diagnostics.rb

Overview

Content-free operational snapshot for health checks and support bundles.

Constant Summary collapse

TABLES =
%w[
  workspace_sessions sessions runs messages run_events workspace_events
  tool_executions artifacts env_data
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Diagnostics

Returns a new instance of Diagnostics.



12
13
14
# File 'lib/prompt_objects/operations/diagnostics.rb', line 12

def initialize(store)
  @store = store
end

Instance Method Details

#snapshot(scheduler: {}, limits: {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/prompt_objects/operations/diagnostics.rb', line 16

def snapshot(scheduler: {}, limits: {})
  data = @store.with_connection do |db|
    runs = db.execute(<<~SQL)
      SELECT status, provider, model, enqueued_at, started_at, finished_at, usage
      FROM runs
    SQL
    tools = db.execute("SELECT status, started_at, finished_at FROM tool_executions")
    {
      schema_version: db.get_first_value("PRAGMA user_version").to_i,
      database: database_stats(db),
      counts: TABLES.to_h { |table| [table.to_sym, db.get_first_value("SELECT COUNT(*) FROM #{table}").to_i] },
      runs: run_stats(runs),
      tools: tool_stats(tools)
    }
  end
  data.merge(
    generated_at: Time.now.utc.iso8601,
    scheduler: scheduler,
    limits: limits
  )
end