claude_memory 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.claude/CLAUDE.md +3 -0
  3. data/.claude/memory.sqlite3 +0 -0
  4. data/.claude/output-styles/memory-aware.md +21 -0
  5. data/.claude/rules/claude_memory.generated.md +21 -0
  6. data/.claude/settings.json +62 -0
  7. data/.claude/settings.local.json +21 -0
  8. data/.claude-plugin/marketplace.json +13 -0
  9. data/.claude-plugin/plugin.json +10 -0
  10. data/.mcp.json +11 -0
  11. data/CHANGELOG.md +36 -0
  12. data/CLAUDE.md +224 -0
  13. data/CODE_OF_CONDUCT.md +10 -0
  14. data/LICENSE.txt +21 -0
  15. data/README.md +212 -0
  16. data/Rakefile +10 -0
  17. data/commands/analyze.md +29 -0
  18. data/commands/recall.md +17 -0
  19. data/commands/remember.md +26 -0
  20. data/docs/demo.md +126 -0
  21. data/docs/organizational_memory_playbook.md +291 -0
  22. data/docs/plan.md +411 -0
  23. data/docs/plugin.md +202 -0
  24. data/docs/updated_plan.md +453 -0
  25. data/exe/claude-memory +8 -0
  26. data/hooks/hooks.json +59 -0
  27. data/lib/claude_memory/cli.rb +869 -0
  28. data/lib/claude_memory/distill/distiller.rb +11 -0
  29. data/lib/claude_memory/distill/extraction.rb +29 -0
  30. data/lib/claude_memory/distill/json_schema.md +78 -0
  31. data/lib/claude_memory/distill/null_distiller.rb +123 -0
  32. data/lib/claude_memory/hook/handler.rb +49 -0
  33. data/lib/claude_memory/index/lexical_fts.rb +58 -0
  34. data/lib/claude_memory/ingest/ingester.rb +46 -0
  35. data/lib/claude_memory/ingest/transcript_reader.rb +21 -0
  36. data/lib/claude_memory/mcp/server.rb +127 -0
  37. data/lib/claude_memory/mcp/tools.rb +409 -0
  38. data/lib/claude_memory/publish.rb +201 -0
  39. data/lib/claude_memory/recall.rb +360 -0
  40. data/lib/claude_memory/resolve/predicate_policy.rb +30 -0
  41. data/lib/claude_memory/resolve/resolver.rb +152 -0
  42. data/lib/claude_memory/store/sqlite_store.rb +340 -0
  43. data/lib/claude_memory/store/store_manager.rb +139 -0
  44. data/lib/claude_memory/sweep/sweeper.rb +80 -0
  45. data/lib/claude_memory/templates/hooks.example.json +74 -0
  46. data/lib/claude_memory/templates/output-styles/memory-aware.md +21 -0
  47. data/lib/claude_memory/version.rb +5 -0
  48. data/lib/claude_memory.rb +36 -0
  49. data/sig/claude_memory.rbs +4 -0
  50. data/skills/analyze/SKILL.md +126 -0
  51. data/skills/memory/SKILL.md +82 -0
  52. metadata +123 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 015ffacff45c0d7976124cbf40c2188d03f3fd182f24de2eab83bd5c0273107e
4
+ data.tar.gz: 68879337aca9ec2b5e9574df1982aead620975b84448cf0ca385d00690619d5b
5
+ SHA512:
6
+ metadata.gz: 3c3ba3ea0f53e035b7ea377bc2c81fc398d7476bfb1019594db274e6aba67e2d92d09420e5f8c08ce1695a0f0128b1cb03d6931df92c172f57f3dc903233c41a
7
+ data.tar.gz: f4f1c185a02b2c5a469dac940e4b06a2cd37a67d0efc4ae8199d4688a2a3511eaf856ea393ecfb9f8972febe6d05cf490c384071a9e349e307d8adf20753219f
data/.claude/CLAUDE.md ADDED
@@ -0,0 +1,3 @@
1
+ # Project Memory
2
+
3
+ @.claude/rules/claude_memory.generated.md
Binary file
@@ -0,0 +1,21 @@
1
+ ---
2
+ keep-coding-instructions: true
3
+ ---
4
+
5
+ # Memory-Aware Output Style
6
+
7
+ When making decisions or establishing conventions:
8
+ - State decisions clearly with "We decided to..." or "We agreed to..."
9
+ - Be explicit about technology choices: "We use PostgreSQL for..."
10
+ - Clarify when replacing previous decisions: "We no longer use X, switching to Y"
11
+ - Note conventions with "Convention:" or "Standard:"
12
+
13
+ When recalling past context:
14
+ - Use the memory.recall MCP tool to find relevant past decisions
15
+ - Cite specific facts when referencing previous work
16
+ - If unsure, use memory.explain to get provenance for a fact
17
+
18
+ When conflicts arise:
19
+ - Acknowledge contradictions explicitly
20
+ - Use memory.conflicts to see open disputes
21
+ - Help resolve conflicts by providing clear supersession signals
@@ -0,0 +1,21 @@
1
+ <!--
2
+ This file is auto-generated by claude-memory.
3
+ Do not edit manually - changes will be overwritten.
4
+ Generated: 2026-01-20T22:15:57Z
5
+ -->
6
+
7
+ # Project Memory
8
+
9
+ ## Conventions
10
+
11
+ - run linting with 'bundle exec rake standard'
12
+ - Ruby 3.2+ required
13
+ - frozen_string_literal: true in all Ruby files
14
+ - Uses Standard Ruby for linting
15
+ - Default task runs tests and linter
16
+ - RSpec uses documentation format
17
+
18
+ ## Technical Constraints
19
+
20
+ - **Uses framework**: Sequel
21
+ - **Uses database**: SQLite3
@@ -0,0 +1,62 @@
1
+ {
2
+ "hooks": {
3
+ "Stop": [
4
+ {
5
+ "matcher": "",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "claude-memory hook ingest --db /Users/valentinostoll/src/claude_memory/.claude/memory.sqlite3",
10
+ "timeout": 10
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "SessionStart": [
16
+ {
17
+ "matcher": "",
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "claude-memory hook ingest --db /Users/valentinostoll/src/claude_memory/.claude/memory.sqlite3",
22
+ "timeout": 10
23
+ }
24
+ ]
25
+ }
26
+ ],
27
+ "PreCompact": [
28
+ {
29
+ "matcher": "",
30
+ "hooks": [
31
+ {
32
+ "type": "command",
33
+ "command": "claude-memory hook ingest --db /Users/valentinostoll/src/claude_memory/.claude/memory.sqlite3",
34
+ "timeout": 30
35
+ },
36
+ {
37
+ "type": "command",
38
+ "command": "claude-memory hook sweep --db /Users/valentinostoll/src/claude_memory/.claude/memory.sqlite3",
39
+ "timeout": 30
40
+ }
41
+ ]
42
+ }
43
+ ],
44
+ "SessionEnd": [
45
+ {
46
+ "matcher": "",
47
+ "hooks": [
48
+ {
49
+ "type": "command",
50
+ "command": "claude-memory hook ingest --db /Users/valentinostoll/src/claude_memory/.claude/memory.sqlite3",
51
+ "timeout": 30
52
+ },
53
+ {
54
+ "type": "command",
55
+ "command": "claude-memory hook sweep --db /Users/valentinostoll/src/claude_memory/.claude/memory.sqlite3",
56
+ "timeout": 30
57
+ }
58
+ ]
59
+ }
60
+ ]
61
+ }
62
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "mcp__claude-memory__memory_changes",
5
+ "mcp__claude-memory__memory_status",
6
+ "mcp__claude-memory__memory_recall",
7
+ "Bash(./exe/claude-memory:*)",
8
+ "mcp__claude-memory__memory_store_extraction",
9
+ "mcp__plugin_claude-memory_claude-memory__memory_store_extraction",
10
+ "mcp__plugin_claude-memory_claude-memory__memory_recall",
11
+ "mcp__plugin_claude-memory_claude-memory__memory_status",
12
+ "mcp__plugin_claude-memory_memory__memory_recall",
13
+ "mcp__memory__memory_recall",
14
+ "mcp__memory__memory_changes",
15
+ "mcp__memory__memory_status",
16
+ "mcp__memory__memory_store_extraction",
17
+ "mcp__memory__memory_explain"
18
+ ]
19
+ },
20
+ "enableAllProjectMcpServers": true
21
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "claude-memory-marketplace",
3
+ "owner": {
4
+ "name": "Valentino Stoll"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "claude-memory",
9
+ "source": "./",
10
+ "description": "Long-term self-managed memory for Claude Code"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "claude-memory",
3
+ "version": "0.1.0",
4
+ "description": "Long-term self-managed memory for Claude Code with fact extraction, truth maintenance, and provenance tracking",
5
+ "author": {
6
+ "name": "Valentino Stoll"
7
+ },
8
+ "license": "MIT",
9
+ "keywords": ["memory", "facts", "knowledge", "persistence"]
10
+ }
data/.mcp.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "memory": {
4
+ "type": "stdio",
5
+ "command": "claude-memory",
6
+ "args": [
7
+ "serve-mcp"
8
+ ]
9
+ }
10
+ }
11
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [Unreleased]
6
+
7
+ ### Added
8
+
9
+ - **Claude Code Plugin**: Full plugin structure for seamless Claude Code integration
10
+ - `.claude-plugin/plugin.json` manifest
11
+ - `.claude-plugin/marketplace.json` for plugin distribution
12
+ - `hooks/hooks.json` with prompt hooks for Claude-powered extraction
13
+ - `skills/memory/SKILL.md` for `/memory` command
14
+ - **Claude-Powered Fact Extraction**: New `memory.store_extraction` MCP tool
15
+ - Accepts structured JSON with entities, facts, and decisions
16
+ - Prompt hooks ask Claude to extract facts on session stop
17
+ - No API key required - uses Claude Code's own session
18
+ - Full schema validation with truth maintenance
19
+ - **Empty Query Handling**: FTS5 search now gracefully handles empty queries
20
+
21
+ ## [0.1.0] - 2026-01-20
22
+
23
+ ### Added
24
+
25
+ - SQLite store with full MVP schema (entities, facts, provenance, conflicts)
26
+ - Transcript delta ingestion with cursor tracking
27
+ - Full-text search via SQLite FTS5
28
+ - NullDistiller for heuristic-based fact extraction
29
+ - Resolver for truth maintenance (supersession/conflict handling)
30
+ - Recall API with provenance receipts
31
+ - Sweep mechanics for time-bounded maintenance
32
+ - MCP server with memory tools
33
+ - Publish command for Claude Code memory integration
34
+ - CLI with all core commands
35
+ - Doctor command for health checks
36
+ - Hooks and output style templates
data/CLAUDE.md ADDED
@@ -0,0 +1,224 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ ClaudeMemory is a Ruby gem that provides long-term, self-managed memory for Claude Code using hooks, MCP tools, and output styles. It ingests transcripts, distills them into facts with provenance, resolves contradictions, and publishes curated snapshots.
8
+
9
+ **Key dependencies:**
10
+ - Ruby 3.2.0+
11
+ - Sequel (~> 5.0) for database access
12
+ - SQLite3 (~> 2.0) for storage
13
+
14
+ ## Development Commands
15
+
16
+ ### Setup
17
+ ```bash
18
+ bin/setup # Install dependencies
19
+ ```
20
+
21
+ ### Testing
22
+ ```bash
23
+ bundle exec rspec # Run all tests
24
+ bundle exec rspec spec/claude_memory/cli_spec.rb # Run single test file
25
+ bundle exec rspec spec/claude_memory/cli_spec.rb:42 # Run specific test by line number
26
+ bundle exec rake spec # Alternative test command
27
+ bundle exec rake # Run tests + Standard linter (default task)
28
+ ```
29
+
30
+ ### Linting
31
+ ```bash
32
+ bundle exec rake standard # Run Standard Ruby linter
33
+ bundle exec rake standard:fix # Auto-fix linting issues
34
+ ```
35
+
36
+ ### Build & Release
37
+ ```bash
38
+ bundle exec rake build # Build gem to pkg/
39
+ bundle exec rake install # Install gem locally
40
+ bundle exec rake release # Tag + push to RubyGems (requires credentials)
41
+ ```
42
+
43
+ ### Running the CLI
44
+ ```bash
45
+ # During development, use the executable directly
46
+ ./exe/claude-memory <command>
47
+
48
+ # Or via bundle exec
49
+ bundle exec claude-memory <command>
50
+ ```
51
+
52
+ ## Architecture
53
+
54
+ ### Dual-Database System
55
+ ClaudeMemory uses two SQLite databases for memory separation:
56
+
57
+ - **Global DB** (`~/.claude/memory.sqlite3`): User-wide knowledge across all projects (preferences, conventions)
58
+ - **Project DB** (`.claude/memory.sqlite3`): Project-specific facts and decisions
59
+
60
+ The `Store::StoreManager` class manages both connections. Commands query both databases by default, with project facts taking precedence.
61
+
62
+ ### Core Pipeline
63
+
64
+ ```
65
+ Transcripts → Ingest → Index (FTS5)
66
+
67
+ Distill → Extract entities/facts + scope hints
68
+
69
+ Resolve → Truth maintenance (supersession/conflicts)
70
+
71
+ Store → SQLite (facts, provenance, entities)
72
+
73
+ Publish → .claude/rules/claude_memory.generated.md
74
+ ```
75
+
76
+ ### Module Structure
77
+
78
+ - **`Store`**: SQLite database access via Sequel (`sqlite_store.rb`, `store_manager.rb`)
79
+ - Schema includes: content_items, entities, facts, provenance, fact_links, conflicts
80
+ - Schema migrations in `ensure_schema!` and `migrate_to_v2!`
81
+
82
+ - **`Ingest`**: Transcript reading and delta-based ingestion (`ingester.rb`, `transcript_reader.rb`)
83
+ - Tracks cursor position per session to avoid re-processing
84
+
85
+ - **`Index`**: Full-text search using SQLite FTS5 (`lexical_fts.rb`)
86
+ - No embeddings required for MVP
87
+
88
+ - **`Distill`**: Fact extraction interface (`distiller.rb`, `null_distiller.rb`)
89
+ - Pluggable distiller design (current: NullDistiller stub)
90
+ - Extracts entities, facts, scope hints from content
91
+
92
+ - **`Resolve`**: Truth maintenance and conflict resolution (`resolver.rb`, `predicate_policy.rb`)
93
+ - Determines equivalence, supersession, or conflicts
94
+ - PredicatePolicy controls single-value vs multi-value predicates
95
+
96
+ - **`Recall`**: Query interface for facts (`recall.rb`)
97
+ - Searches both global + project databases
98
+ - Returns facts with provenance receipts
99
+
100
+ - **`Sweep`**: Maintenance and pruning (`sweeper.rb`)
101
+
102
+ - **`Publish`**: Snapshot generation to Claude Code memory files (`publish.rb`)
103
+ - Modes: shared (repo), local (uncommitted), home (user directory)
104
+
105
+ - **`MCP`**: Model Context Protocol server and tools (`mcp/server.rb`, `mcp/tools.rb`)
106
+ - Exposes memory tools to Claude Code: recall, explain, promote, status, conflicts, changes, sweep_now
107
+
108
+ - **`Hook`**: Hook entrypoint handlers (`hook/handler.rb`)
109
+ - Reads stdin JSON from Claude Code hooks
110
+ - Routes to ingest/sweep/publish commands
111
+
112
+ - **`CLI`**: Command-line interface (`cli.rb`)
113
+ - All user-facing commands and option parsing
114
+
115
+ ### Database Schema
116
+
117
+ Key tables (defined in `sqlite_store.rb`):
118
+ - `content_items`: Ingested transcript chunks with cursor tracking
119
+ - `entities`: Named entities (people, repos, concepts)
120
+ - `entity_aliases`: Alternative names for entities
121
+ - `facts`: Subject-predicate-object triples with validity windows and scope
122
+ - `provenance`: Links facts to source content_items
123
+ - `fact_links`: Supersession and conflict relationships
124
+ - `conflicts`: Open contradictions
125
+
126
+ Facts include:
127
+ - `scope`: "global" or "project" (determines applicability)
128
+ - `project_path`: Set for project-scoped facts
129
+ - `valid_from`/`valid_to`: Temporal validity window
130
+
131
+ ### Scope System
132
+
133
+ Facts are scoped to control where they apply:
134
+ - **project**: Current project only (e.g., "this app uses PostgreSQL")
135
+ - **global**: All projects (e.g., "I prefer 4-space indentation")
136
+
137
+ Distiller detects signals like "always", "in all projects", "my preference" and sets `scope_hint: "global"`. Users can manually promote facts via `claude-memory promote <fact_id>` or the `memory.promote` MCP tool.
138
+
139
+ ## Testing Strategy
140
+
141
+ Tests are in `spec/claude_memory/` organized by module. Use RSpec's `--format documentation` for readable output.
142
+
143
+ When writing tests:
144
+ - Mock external dependencies (file I/O, database where appropriate)
145
+ - Use `let` blocks for shared test data
146
+ - Focus on behavior, not implementation details
147
+
148
+ ## Common Development Tasks
149
+
150
+ ### Adding a New CLI Command
151
+
152
+ 1. Add command name to `CLI#run` case statement
153
+ 2. Implement private method (e.g., `my_command_cmd`)
154
+ 3. Add parser method (e.g., `parse_my_command_options`)
155
+ 4. Update `print_help` output
156
+ 5. Add corresponding tests in `spec/claude_memory/cli_spec.rb`
157
+
158
+ ### Adding a New MCP Tool
159
+
160
+ 1. Add tool definition to `MCP::Tools::TOOLS` hash
161
+ 2. Implement handler in `MCP::Server#handle_tool_call`
162
+ 3. Ensure tool queries appropriate database(s) via StoreManager
163
+ 4. Add tests in `spec/claude_memory/mcp/`
164
+
165
+ ### Modifying Database Schema
166
+
167
+ 1. Increment `SCHEMA_VERSION` in `sqlite_store.rb`
168
+ 2. Add migration method (e.g., `migrate_to_v3!`)
169
+ 3. Call migration in `run_migrations!`
170
+ 4. Test migration on existing database files
171
+ 5. Update documentation if schema changes affect external interfaces
172
+
173
+ ### Adding a New Predicate Policy
174
+
175
+ Single-value predicates (like "uses_database") supersede old values. Multi-value predicates (like "depends_on") accumulate. Modify `PredicatePolicy.single?` to adjust behavior.
176
+
177
+ ## Important Files
178
+
179
+ - `lib/claude_memory.rb`: Main module, requires, database path helpers
180
+ - `lib/claude_memory/cli.rb`: All CLI command implementations (800+ lines)
181
+ - `lib/claude_memory/store/store_manager.rb`: Dual-database connection manager
182
+ - `lib/claude_memory/resolve/resolver.rb`: Truth maintenance logic
183
+ - `lib/claude_memory/recall.rb`: Fact query and merging logic
184
+ - `docs/updated_plan.md`: Comprehensive architectural plan and milestones
185
+ - `claude_memory.gemspec`: Gem metadata and dependencies
186
+
187
+ ## MCP Integration
188
+
189
+ The gem includes an MCP server (`claude-memory serve-mcp`) that exposes memory operations as tools. Configuration should be in `.mcp.json` at project root.
190
+
191
+ Available MCP tools:
192
+ - `memory.recall` - Search for relevant facts (scope filtering supported)
193
+ - `memory.explain` - Get detailed fact provenance
194
+ - `memory.promote` - Promote project fact to global
195
+ - `memory.status` - Health check for both databases
196
+ - `memory.changes` - Recent fact updates
197
+ - `memory.conflicts` - Open contradictions
198
+ - `memory.sweep_now` - Run maintenance
199
+
200
+ ## Hook Integration
201
+
202
+ ClaudeMemory integrates with Claude Code via hooks in `.claude/settings.json`:
203
+
204
+ - **Ingest hook**: Triggers on Stop/SessionStart/PreCompact events
205
+ - Calls `claude-memory hook ingest` with stdin JSON
206
+ - Reads transcript delta and updates both global and project databases
207
+
208
+ - **Sweep hook**: Triggers on idle_prompt and safety events
209
+ - Runs time-bounded maintenance on both databases
210
+
211
+ - **Publish hook**: Optional, on SessionEnd/PreCompact
212
+ - Publishes curated snapshot to `.claude/rules/`
213
+
214
+ Hook commands read JSON payloads from stdin for robustness.
215
+
216
+ ## Code Style
217
+
218
+ This project uses [Standard Ruby](https://github.com/standardrb/standard) for linting. Run `bundle exec rake standard:fix` before committing.
219
+
220
+ Key conventions:
221
+ - Use `frozen_string_literal: true` at top of all Ruby files
222
+ - Prefer explicit returns only when control flow is complex
223
+ - Use Sequel's dataset methods (avoid raw SQL where possible)
224
+ - Keep CLI commands focused; extract complex logic to dedicated classes
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "claude_memory" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["v@codenamev.com"](mailto:"v@codenamev.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Valentino Stoll
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.