Class: ClaudeMemory::Publish

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

Overview

Generates Markdown snapshots from active facts for use as project memory. Publishes to .claude/rules/ (shared), a local file, or the home directory.

Constant Summary collapse

RULES_DIR =
".claude/rules"
GENERATED_FILE =
"claude_memory.generated.md"

Instance Method Summary collapse

Constructor Details

#initialize(store, file_system: Infrastructure::FileSystem.new) ⇒ Publish

Returns a new instance of Publish.

Parameters:



15
16
17
18
# File 'lib/claude_memory/publish.rb', line 15

def initialize(store, file_system: Infrastructure::FileSystem.new)
  @store = store
  @fs = file_system
end

Instance Method Details

#generate_snapshot(since: nil) ⇒ String

Generate a complete Markdown snapshot with header and body

Parameters:

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

    ISO 8601 timestamp to include recent supersessions

Returns:

  • (String)

    full Markdown document



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/claude_memory/publish.rb', line 23

def generate_snapshot(since: nil)
  header = <<~HEADER
    <!--
      This file is auto-generated by claude-memory.
      Do not edit manually - changes will be overwritten.
      Generated: #{Time.now.utc.iso8601}
    -->

    # Project Memory

  HEADER

  header + generate_body(since: since)
end

#publish!(mode: :shared, granularity: :repo, since: nil, rules_dir: nil) ⇒ Hash

Write snapshot to disk if content has changed

Parameters:

  • mode (Symbol) (defaults to: :shared)

    output target (:shared, :local, or :home)

  • granularity (Symbol) (defaults to: :repo)

    snapshot granularity (currently only :repo)

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

    ISO 8601 timestamp for recent supersessions

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

    override rules directory path

Returns:

  • (Hash)

    result with :status (:updated or :unchanged) and :path



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/claude_memory/publish.rb', line 44

def publish!(mode: :shared, granularity: :repo, since: nil, rules_dir: nil)
  path = output_path(mode, rules_dir: rules_dir)
  body = generate_body(since: since)

  if should_write?(path, body)
    content = generate_snapshot(since: since)
    @fs.write(path, content)
    ensure_import_exists(mode, path, rules_dir: rules_dir)
    {status: :updated, path: path}
  else
    {status: :unchanged, path: path}
  end
end