Class: ClaudeMemory::Commands::ShowCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/claude_memory/commands/show_command.rb

Overview

Prints what memory would inject on the next SessionStart.

The trust answer to “is this still worth it?” requires inspectability: a user who can’t see what memory will inject can’t develop confidence in it. The CLAUDE.md alternative is ‘cat CLAUDE.md` — instant, plain English, no tooling. This command is the same one-line inspect surface for the curated facts the injector picks each session.

Runs the exact ‘Hook::ContextInjector` path real sessions use, so what you see here is what Claude actually receives — not a rebuilt approximation that could drift.

The default suppresses the “Pending Knowledge Extraction” dump (which contains raw transcript JSON intended for LLM distillation) so the output stays human-readable. Pass ‘–pending` to see the full fresh-session payload, including those raw items.

Constant Summary collapse

VALID_SOURCES =
%w[startup resume clear].freeze
NON_FRESH_SOURCE =

Any string outside FRESH_SESSION_SOURCES skips the pending-knowledge block. “preview” reads naturally in any debug log this surfaces in.

"preview"

Instance Attribute Summary

Attributes inherited from BaseCommand

#stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from ClaudeMemory::Commands::BaseCommand

Instance Method Details

#call(args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/claude_memory/commands/show_command.rb', line 31

def call(args)
  opts = parse_options(args, {source: nil, pending: false}) do |o|
    OptionParser.new do |parser|
      parser.banner = "Usage: claude-memory show [--source SOURCE] [--pending]"
      parser.on("--source SOURCE", VALID_SOURCES,
        "Simulate fresh-session source (#{VALID_SOURCES.join(", ")}). " \
        "Forces inclusion of pending-knowledge and auto-memory-mirror " \
        "sections regardless of --pending.") { |v| o[:source] = v }
      parser.on("--pending",
        "Include the pending-knowledge dump (raw transcript JSON " \
        "for LLM distillation). Default suppresses it for readability.") { o[:pending] = true }
    end
  end
  return 1 if opts.nil?

  effective_source = opts[:source] || (opts[:pending] ? nil : NON_FRESH_SOURCE)

  manager = Store::StoreManager.new
  manager.ensure_both!
  injector = Hook::ContextInjector.new(manager, source: effective_source)
  context = injector.generate_context

  print_header(opts[:source])
  stdout.puts ""

  if context.nil? || context.strip.empty?
    stdout.puts "_Memory has no facts to inject yet._"
    stdout.puts ""
    stdout.puts "Run a few Claude Code sessions in this project, or use"
    stdout.puts "`memory.store_extraction` from a session to seed facts."
  else
    stdout.puts context
    stdout.puts ""
    print_footer(injector, context)
  end

  manager.close
  0
rescue Sequel::DatabaseError => e
  failure("Database error: #{e.message}")
end