claude-recall 0.7.9 → 0.8.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.
package/.claude/CLAUDE.md CHANGED
@@ -15,8 +15,8 @@ This file provides instructions to Claude Code when working with projects that u
15
15
 
16
16
  Your job is to:
17
17
  1. Remember stated preferences permanently
18
- 2. Learn from successes (what worked)
19
- 3. Learn from failures (what didn't work)
18
+ 2. Learn from failures and corrections (what didn't work, how it was fixed)
19
+ 3. Capture meaningful success patterns (when overcoming challenges, not trivial actions)
20
20
  4. Apply learned patterns automatically
21
21
 
22
22
  ## The Learning Loop Workflow
@@ -55,15 +55,7 @@ Apply what you found:
55
55
 
56
56
  ### Phase 3: Post-Action (AFTER task completion)
57
57
 
58
- **Capture the outcome** for future learning by storing directly:
59
-
60
- **If user approves** ("Good!", "Perfect!", "Thanks!"):
61
- ```
62
- mcp__claude-recall__store_memory({
63
- content: "Created [what you did] - SUCCESS",
64
- metadata: { type: "success", task: "[task type]" }
65
- })
66
- ```
58
+ **Capture meaningful outcomes** for future learning:
67
59
 
68
60
  **If user corrects** ("No, do it this way", "Change X to Y"):
69
61
  ```
@@ -75,9 +67,26 @@ mcp__claude-recall__store_memory({
75
67
 
76
68
  **If task fails** (errors, "That didn't work"):
77
69
  ```
70
+ Failures are AUTO-CAPTURED with counterfactual reasoning.
71
+ No manual storage needed - the system detects failures automatically.
72
+ ```
73
+
74
+ **If task succeeds AFTER overcoming challenges** (fail → correct → success):
75
+ ```
76
+ ONLY store success when there was a learning cycle:
77
+ - After you tried approach A, failed, then approach B worked
78
+ - After user corrected your approach and THEN it succeeded
79
+ - When task required multiple iterations to get right
80
+
81
+ DO NOT store success for:
82
+ - Trivial tool executions (creating files, running commands)
83
+ - First-try successes with no challenges
84
+ - Actions that just followed existing preferences
85
+
86
+ Example of meaningful success:
78
87
  mcp__claude-recall__store_memory({
79
- content: "[Approach] failed - [reason]",
80
- metadata: { type: "failure", avoid: true }
88
+ content: "Tried session-based auth (failed), switched to JWT tokens (SUCCESS) - JWT works better for stateless API",
89
+ metadata: { type: "success", task: "authentication", learning_cycle: true }
81
90
  })
82
91
  ```
83
92
 
@@ -182,10 +191,8 @@ Confirm: "✓ Stored preference"
182
191
 
183
192
  3. User responds: "Perfect!"
184
193
 
185
- 4. Store success: mcp__claude-recall__store_memory({
186
- content: "Created test script with Python - SUCCESS",
187
- metadata: { type: "success", task: "test_script" }
188
- })
194
+ 4. DO NOT store success - this was just applying a known preference
195
+ No challenge overcome, no learning cycle.
189
196
  ```
190
197
 
191
198
  ### Third Time - Automatic Application
@@ -195,14 +202,31 @@ Confirm: "✓ Stored preference"
195
202
  **You (Claude Code):**
196
203
  ```
197
204
  1. Search: mcp__claude-recall__search("scripts build python")
198
- Finds:
199
- - "I prefer Python for scripts" (preference)
200
- - "Created test script with Python - SUCCESS" (validates preference)
205
+ Finds: "I prefer Python for scripts" (preference)
201
206
 
202
- 2. Create build.py automatically - preference + success pattern!
207
+ 2. Create build.py automatically - preference applied!
203
208
  User doesn't have to repeat themselves ✓
204
209
  ```
205
210
 
211
+ ### Learning Cycle Example - When to Store Success
212
+
213
+ **User:** "Set up authentication"
214
+
215
+ **You (Claude Code):**
216
+ ```
217
+ 1. Try approach: Create session-based auth with cookies
218
+ 2. Error: "CORS issues in stateless API"
219
+ 3. User feedback: "This is a stateless API, sessions won't work"
220
+ 4. Try approach: JWT tokens with Bearer authentication
221
+ 5. Success! Works correctly.
222
+
223
+ 6. ✓ STORE THIS - it's a learning cycle:
224
+ mcp__claude-recall__store_memory({
225
+ content: "Session auth failed for stateless API (CORS). JWT tokens work - use Bearer authentication for stateless APIs",
226
+ metadata: { type: "success", task: "authentication", learning_cycle: true }
227
+ })
228
+ ```
229
+
206
230
  ### User Makes Correction
207
231
 
208
232
  **User:** "No, put scripts in scripts/ directory not root"
@@ -225,11 +249,17 @@ Confirm: "✓ Stored preference"
225
249
  - States a preference ("I prefer X", "Always use Y", "Never do Z")
226
250
  - Makes a decision ("We're using X framework")
227
251
  - Provides project info ("Our API uses X pattern")
252
+ - Makes a correction ("No, do it this way", "Change X to Y")
253
+
254
+ **Store after task completion (ONLY for learning cycles):**
255
+ - **Success (rare!)**: Only when overcoming challenges - "Tried X (failed), then Y (SUCCESS)"
256
+ - **Failure (auto-captured)**: System detects automatically, no manual storage needed
257
+ - **Correction**: Always store user corrections with high priority
228
258
 
229
- **Store after task completion:**
230
- - Success: "Created X with Y approach - SUCCESS"
231
- - Failure: "Approach X failed - use Y instead"
232
- - Correction: "CORRECTION: User prefers Y not X"
259
+ **DO NOT store:**
260
+ - Trivial successes (file creation, simple tool execution)
261
+ - First-try successes with no challenges
262
+ - Actions that just followed existing preferences
233
263
 
234
264
  ## Critical Guidelines
235
265
 
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PubNub-enabled pre-tool hook for Claude Recall.
4
+
5
+ This lightweight hook:
6
+ 1. Publishes tool execution event to PubNub (async, non-blocking)
7
+ 2. Allows execution to proceed immediately
8
+ 3. Memory Agent subscribes to events and provides context asynchronously
9
+
10
+ No blocking, no waiting - just publish and continue.
11
+ This makes hooks fast and Claude Code responsive.
12
+
13
+ Exit codes:
14
+ - 0: Always allow (non-blocking design)
15
+ """
16
+ import json
17
+ import sys
18
+ import subprocess
19
+ import os
20
+ from typing import Dict, Any
21
+
22
+ # Path to Node.js publisher
23
+ PUBLISHER_PATH = os.path.join(
24
+ os.path.dirname(os.path.dirname(__file__)),
25
+ 'dist', 'pubnub', 'publisher-cli.js'
26
+ )
27
+
28
+
29
+ def publish_tool_event(hook_data: Dict[str, Any]) -> bool:
30
+ """
31
+ Publish tool execution event to PubNub.
32
+ Fire-and-forget - doesn't wait for response.
33
+ """
34
+ try:
35
+ tool_name = hook_data.get('tool_name', '')
36
+ tool_input = hook_data.get('tool_input', {})
37
+ session_id = hook_data.get('session_id', '')
38
+ project_id = hook_data.get('project_id', '')
39
+
40
+ # Construct event data
41
+ event_data = {
42
+ 'sessionId': session_id,
43
+ 'toolName': tool_name,
44
+ 'toolInput': tool_input,
45
+ 'projectId': project_id
46
+ }
47
+
48
+ # Publish via Node.js CLI (non-blocking)
49
+ subprocess.Popen(
50
+ ['node', PUBLISHER_PATH, 'tool-pre', json.dumps(event_data)],
51
+ stdout=subprocess.DEVNULL,
52
+ stderr=subprocess.DEVNULL,
53
+ start_new_session=True # Detach from parent
54
+ )
55
+
56
+ return True
57
+
58
+ except Exception as e:
59
+ # Never block on errors - just log and continue
60
+ print(f"[PubNub Hook] Warning: Event publish failed: {e}", file=sys.stderr)
61
+ return False
62
+
63
+
64
+ def main():
65
+ """
66
+ Main hook entry point.
67
+ Always allows execution - memory context will arrive asynchronously.
68
+ """
69
+ try:
70
+ # Read hook data from stdin
71
+ hook_data = json.load(sys.stdin)
72
+
73
+ # Publish event (non-blocking)
74
+ publish_tool_event(hook_data)
75
+
76
+ # Always allow execution to proceed
77
+ # Memory Agent will provide context asynchronously via PubNub
78
+ sys.exit(0)
79
+
80
+ except json.JSONDecodeError as e:
81
+ # Parse error - log warning but don't block
82
+ print(f"[PubNub Hook] Warning: Failed to parse hook input: {e}", file=sys.stderr)
83
+ sys.exit(0)
84
+
85
+ except Exception as e:
86
+ # Any other error - log but don't block
87
+ print(f"[PubNub Hook] Warning: Hook error: {e}", file=sys.stderr)
88
+ sys.exit(0)
89
+
90
+
91
+ if __name__ == '__main__':
92
+ main()
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PubNub-enabled prompt capture hook for Claude Recall.
4
+
5
+ Publishes user prompts to PubNub for the Memory Agent to analyze
6
+ and extract preferences/patterns autonomously.
7
+
8
+ Non-blocking, fire-and-forget design.
9
+
10
+ Exit codes:
11
+ - 0: Always allow (non-blocking)
12
+ """
13
+ import json
14
+ import sys
15
+ import subprocess
16
+ import os
17
+ from typing import Dict, Any
18
+
19
+ # Path to Node.js publisher
20
+ PUBLISHER_PATH = os.path.join(
21
+ os.path.dirname(os.path.dirname(__file__)),
22
+ 'dist', 'pubnub', 'publisher-cli.js'
23
+ )
24
+
25
+
26
+ def publish_prompt_event(hook_data: Dict[str, Any]) -> bool:
27
+ """
28
+ Publish user prompt to PubNub for Memory Agent analysis.
29
+ Fire-and-forget - doesn't wait for response.
30
+ """
31
+ try:
32
+ # Extract prompt content (handle different Claude Code versions)
33
+ prompt_content = (
34
+ hook_data.get('prompt', '') or
35
+ hook_data.get('content', '') or
36
+ hook_data.get('message', '')
37
+ )
38
+
39
+ if not prompt_content:
40
+ return False
41
+
42
+ session_id = hook_data.get('session_id', '')
43
+ project_id = hook_data.get('project_id', '')
44
+
45
+ # Construct event data
46
+ event_data = {
47
+ 'sessionId': session_id,
48
+ 'content': prompt_content,
49
+ 'projectId': project_id
50
+ }
51
+
52
+ # Publish via Node.js CLI (non-blocking)
53
+ subprocess.Popen(
54
+ ['node', PUBLISHER_PATH, 'prompt', json.dumps(event_data)],
55
+ stdout=subprocess.DEVNULL,
56
+ stderr=subprocess.DEVNULL,
57
+ start_new_session=True # Detach from parent
58
+ )
59
+
60
+ return True
61
+
62
+ except Exception as e:
63
+ # Never block on errors
64
+ print(f"[PubNub Hook] Warning: Prompt publish failed: {e}", file=sys.stderr)
65
+ return False
66
+
67
+
68
+ def main():
69
+ """
70
+ Main hook entry point.
71
+ Always allows execution - prompt analysis happens asynchronously.
72
+ """
73
+ try:
74
+ # Read hook data from stdin
75
+ hook_data = json.load(sys.stdin)
76
+
77
+ # Publish prompt event (non-blocking)
78
+ publish_prompt_event(hook_data)
79
+
80
+ # Always allow prompt to proceed
81
+ sys.exit(0)
82
+
83
+ except json.JSONDecodeError as e:
84
+ print(f"[PubNub Hook] Warning: Failed to parse hook input: {e}", file=sys.stderr)
85
+ sys.exit(0)
86
+
87
+ except Exception as e:
88
+ print(f"[PubNub Hook] Warning: Hook error: {e}", file=sys.stderr)
89
+ sys.exit(0)
90
+
91
+
92
+ if __name__ == '__main__':
93
+ main()
@@ -0,0 +1,25 @@
1
+ {
2
+ "hooks": {
3
+ "PreToolUse": [
4
+ {
5
+ "matcher": "Write|Edit",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "python3 .claude/hooks/pubnub_pre_tool_hook.py"
10
+ }
11
+ ]
12
+ }
13
+ ],
14
+ "UserPromptSubmit": [
15
+ {
16
+ "hooks": [
17
+ {
18
+ "type": "command",
19
+ "command": "python3 .claude/hooks/pubnub_prompt_hook.py"
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
25
+ }
@@ -31,9 +31,9 @@ This Skill teaches Claude Code how to use Claude Recall's persistent memory syst
31
31
  - Code style, framework preferences
32
32
  - File organization, naming conventions
33
33
 
34
- 4. **Success/Failure** (Priority 3) - What worked and what didn't
35
- - Successful implementations to repeat
36
- - Failed approaches to avoid
34
+ 4. **Success/Failure** (Priority 3) - Learning cycles only
35
+ - **Success (rare!)**: Only when overcoming challenges - fail → correct → success cycles
36
+ - **Failure (auto-captured)**: System detects failures automatically with counterfactual reasoning
37
37
 
38
38
  ## Phase 1: Search Memories (REQUIRED FIRST STEP)
39
39
 
@@ -73,8 +73,8 @@ mcp__claude-recall__search("deploy build docker git workflow")
73
73
 
74
74
  - **DevOps workflows**: Git branching, testing rules, deployment steps
75
75
  - **Preferences**: User's stated coding style, tool choices
76
- - **Successes**: Past approaches that worked well
77
- - **Failures**: Past approaches that failed (avoid these!)
76
+ - **Learning cycles**: Approaches that overcame challenges (fail → correct → success)
77
+ - **Failures (auto-captured)**: Past approaches that failed (avoid these!)
78
78
  - **Corrections**: User fixes (HIGHEST PRIORITY - user explicitly said "no, do this")
79
79
 
80
80
  ## When to Store Memories
@@ -196,11 +196,9 @@ Finds: "I prefer Python for scripts" + "We use TDD"
196
196
 
197
197
  Step 2: Create test_script.py with TDD approach
198
198
 
199
- Step 3: User approves → Store success
200
- mcp__claude-recall__store_memory({
201
- content: "Created test script with Python + TDD - SUCCESS",
202
- metadata: { type: "success", task: "test_script" }
203
- })
199
+ Step 3: User approves
200
+ ✗ DO NOT store success - this was just applying known preferences
201
+ No challenge overcome, no learning cycle
204
202
  ```
205
203
 
206
204
  ### Third Time (Automatic Application)
@@ -213,12 +211,34 @@ mcp__claude-recall__search("script build python tdd")
213
211
  Finds:
214
212
  - "I prefer Python for scripts" (preference)
215
213
  - "We use TDD" (devops)
216
- - "Created test script with Python + TDD - SUCCESS" (validates approach)
217
214
 
218
215
  Step 2: Create build.py with tests automatically
219
216
  User doesn't have to repeat preferences! ✓
220
217
  ```
221
218
 
219
+ ### Learning Cycle Example (When to Store Success)
220
+
221
+ ```
222
+ User: "Integrate with payment API"
223
+
224
+ Step 1: Try REST approach
225
+ - Built REST client with fetch()
226
+ - Error: "CORS blocked in production"
227
+
228
+ Step 2: User feedback
229
+ User: "Our infra doesn't support CORS, use GraphQL endpoint"
230
+
231
+ Step 3: Switch to GraphQL
232
+ - Implemented GraphQL client
233
+ - SUCCESS! Works in production
234
+
235
+ Step 4: ✓ STORE THIS - it's a learning cycle
236
+ mcp__claude-recall__store_memory({
237
+ content: "Payment API: REST failed (CORS blocked). GraphQL endpoint works - use GraphQL for all payment integrations",
238
+ metadata: { type: "success", task: "payment_api", learning_cycle: true }
239
+ })
240
+ ```
241
+
222
242
  ## Best Practices
223
243
 
224
244
  1. **Search broadly** - Include task type + language + workflow keywords
@@ -5,45 +5,73 @@ This document provides templates for manually storing memories when automatic ca
5
5
  ## When to Use Manual Storage
6
6
 
7
7
  Use `mcp__claude-recall__store_memory` when:
8
- - Complex multi-step workflows need to be documented
9
- - Lessons learned from failures
10
- - User corrects your work
11
- - Nuanced context that patterns might miss
8
+ - **User corrects your work** (highest priority)
9
+ - **Learning cycles** - When you overcame a challenge (tried A, failed, then B worked)
10
+ - **Complex multi-step workflows** need to be documented
11
+ - **Nuanced context** that automatic capture might miss
12
12
 
13
- ## Success Examples
13
+ **DO NOT** use for:
14
+ - Trivial successes (file creation, simple tool execution)
15
+ - First-try successes with no challenges
16
+ - Actions that just followed existing preferences
14
17
 
15
- ### Basic Success
18
+ ## Success Examples (Learning Cycles Only!)
19
+
20
+ **IMPORTANT**: Only store success memories when there was a **learning cycle** - you tried something, it failed, then another approach worked. This captures valuable insights, not trivial actions.
21
+
22
+ ### Learning Cycle: Authentication Approach
16
23
  ```javascript
24
+ // ✓ Store this - overcame a challenge
17
25
  mcp__claude-recall__store_memory({
18
- content: "Created authentication with JWT tokens - SUCCESS",
19
- metadata: { type: "success", task: "authentication" }
26
+ content: "Tried session-based auth with cookies (FAILED - CORS issues in distributed API). Switched to JWT tokens with Bearer auth - SUCCESS. JWT works better for stateless architecture.",
27
+ metadata: {
28
+ type: "success",
29
+ task: "authentication",
30
+ learning_cycle: true,
31
+ failed_approach: "session_cookies",
32
+ working_approach: "jwt_bearer"
33
+ }
20
34
  })
21
35
  ```
22
36
 
23
- ### Success with Context
37
+ ### Learning Cycle: Audio Capture Strategy
24
38
  ```javascript
39
+ // ✓ Store this - iterated to find the right solution
25
40
  mcp__claude-recall__store_memory({
26
- content: "Implemented push-to-talk with pyaudio instead of continuous VAD - SUCCESS. Much better performance and user control.",
41
+ content: "Continuous VAD approach failed (too CPU intensive). Tried buffering (FAILED - lag issues). Implemented push-to-talk with pyaudio - SUCCESS. Much better performance and UX control.",
27
42
  metadata: {
28
43
  type: "success",
29
44
  task: "audio_capture",
45
+ learning_cycle: true,
30
46
  improvement: "performance + ux"
31
47
  }
32
48
  })
33
49
  ```
34
50
 
35
- ### Success with Technical Details
51
+ ### Learning Cycle: Performance Fix
36
52
  ```javascript
53
+ // ✓ Store this - debugging led to solution
37
54
  mcp__claude-recall__store_memory({
38
- content: "Fixed memory leak by moving PyAudio initialization outside the loop - SUCCESS. Memory usage dropped from 500MB to 50MB.",
55
+ content: "Memory leak investigation: Tried garbage collection tuning (no effect). Checked event listeners (not the issue). Found PyAudio initialization inside loop - moved outside - SUCCESS. Memory dropped 500MB 50MB.",
39
56
  metadata: {
40
57
  type: "success",
41
58
  task: "performance",
59
+ learning_cycle: true,
42
60
  metric: "10x memory reduction"
43
61
  }
44
62
  })
45
63
  ```
46
64
 
65
+ ### ✗ DON'T Store Trivial Success
66
+ ```javascript
67
+ // ✗ DON'T store this - no challenge, just basic tool execution
68
+ mcp__claude-recall__store_memory({
69
+ content: "Created authentication module with JWT - SUCCESS",
70
+ metadata: { type: "success", task: "authentication" }
71
+ })
72
+ // Why not? No failure, no iteration, no learning cycle.
73
+ ```
74
+
47
75
  ## Failure Examples
48
76
 
49
77
  ### Basic Failure