Class: ClaudeMemory::Publish
- Inherits:
-
Object
- Object
- ClaudeMemory::Publish
- 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"- OBSERVATIONS_FILE =
"claude_memory.observations.md"- MAX_PUBLISHED_OBSERVATIONS =
50
Instance Method Summary collapse
-
#generate_snapshot(since: nil) ⇒ String
Generate a complete Markdown snapshot with header and body.
-
#initialize(store, file_system: Infrastructure::FileSystem.new) ⇒ Publish
constructor
A new instance of Publish.
-
#publish!(mode: :shared, granularity: :repo, since: nil, rules_dir: nil) ⇒ Hash
Write snapshot to disk if content has changed.
-
#publish_observations!(mode: :shared, rules_dir: nil) ⇒ Hash
Write the episodic observation log to .claude/rules/ when there are observations to show.
Constructor Details
#initialize(store, file_system: Infrastructure::FileSystem.new) ⇒ Publish
Returns a new instance of Publish.
17 18 19 20 |
# File 'lib/claude_memory/publish.rb', line 17 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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/claude_memory/publish.rb', line 25 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/claude_memory/publish.rb', line 46 def publish!(mode: :shared, granularity: :repo, since: nil, rules_dir: nil) path = output_path(mode, rules_dir: rules_dir) body = generate_body(since: since) result = 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 # The episodic observation log is published as a sibling artifact, not # imported into CLAUDE.md — it reaches the session via the SessionStart # context hook (Block 1). The file is a durable, diff-able snapshot. publish_observations!(mode: mode, rules_dir: rules_dir) result end |
#publish_observations!(mode: :shared, rules_dir: nil) ⇒ Hash
Write the episodic observation log to .claude/rules/ when there are observations to show. Mirrors publish!‘s change-detection so the file is only rewritten when its body changes.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/claude_memory/publish.rb', line 72 def publish_observations!(mode: :shared, rules_dir: nil) body = observations_body path = observations_path(mode, rules_dir: rules_dir) return {status: :empty, path: path} if body.nil? if should_write?(path, body) @fs.write(path, observations_snapshot(body)) {status: :updated, path: path} else {status: :unchanged, path: path} end end |