Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05ddf3540c | |||
| adc5853c73 | |||
| 81fdf28347 | |||
| b3a565c448 | |||
| 5b28c23b20 | |||
| f4217cb2b9 | |||
| e7252c8999 | |||
| 74637705d7 | |||
| 322cb94c43 | |||
| 21c7ab2929 | |||
| 3846d66ccc | |||
| 817a069323 |
@@ -10,7 +10,7 @@
|
||||
"plugins": [
|
||||
{
|
||||
"name": "claude-mem",
|
||||
"version": "4.2.4",
|
||||
"version": "4.2.9",
|
||||
"source": "./plugin",
|
||||
"description": "Persistent memory system for Claude Code - context compression across sessions"
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Claude-mem is a persistent memory compression system that preserves context across Claude Code sessions. It automatically captures tool usage observations, processes them through the Claude Agent SDK, and makes summaries available to future sessions.
|
||||
|
||||
**Current Version**: 4.2.4
|
||||
**Current Version**: 4.2.9
|
||||
**License**: AGPL-3.0
|
||||
**Author**: Alex Newman (@thedotmack)
|
||||
|
||||
@@ -210,7 +210,125 @@ npm run build && git commit -a -m "Build and update" && git push && cd ~/.claude
|
||||
|
||||
## Version History
|
||||
|
||||
### v4.2.4 (Current)
|
||||
### v4.2.9 (Current)
|
||||
**Breaking Changes**: None (patch version)
|
||||
|
||||
**Documentation**:
|
||||
- Added experimental progressive disclosure context system documentation
|
||||
- New README section explaining the 3-layer memory retrieval approach
|
||||
- Created `EXPERIMENTAL_RELEASE_NOTES.md` with comprehensive testing guide
|
||||
- Created `GITHUB_RELEASE_TEMPLATE.md` for release announcements
|
||||
- Invites users to test `feature/context-with-observations` branch
|
||||
- Progressive disclosure concept: Index (what exists + token costs) → Details (on-demand via MCP) → Perfect recall (source code)
|
||||
- Seeks user feedback on observation-level context injection vs current summary-only approach
|
||||
|
||||
**Purpose**:
|
||||
- Gather real-world feedback before merging experimental context improvements
|
||||
- Test whether showing observation index improves Claude's retrieval decisions
|
||||
- Validate token cost metadata influences Claude's search behavior
|
||||
|
||||
**Files Changed**:
|
||||
- `README.md` - Added experimental feature section
|
||||
- `EXPERIMENTAL_RELEASE_NOTES.md` - Full testing guide and feedback template
|
||||
- `GITHUB_RELEASE_TEMPLATE.md` - Release announcement template
|
||||
- Updated all version references to 4.2.9
|
||||
|
||||
### v4.2.8
|
||||
**Breaking Changes**: None (patch version)
|
||||
|
||||
**Critical Bugfix**:
|
||||
- Fixed NOT NULL constraint violation that prevented observations and summaries from being stored
|
||||
- Root cause: `SessionStore.getSessionById()` was not selecting `claude_session_id` from database
|
||||
- Worker service received `undefined` for `claude_session_id` when initializing sessions
|
||||
- Result: Database inserts failed with "NOT NULL constraint failed: sdk_sessions.claude_session_id"
|
||||
- Fix: Added `claude_session_id` to SELECT query and return type in `getSessionById()`
|
||||
- Impact: Session ID from hooks now flows correctly: hook → database → worker → SDK agent
|
||||
- Affects: All observation and summary storage operations
|
||||
|
||||
**Technical Details**:
|
||||
- Updated `src/services/sqlite/SessionStore.ts:711` to include `claude_session_id` in SELECT
|
||||
- Updated return type signature to include `claude_session_id: string` field
|
||||
- Worker service now correctly receives and uses `claude_session_id` from database
|
||||
- System maintains consistency throughout entire session lifecycle
|
||||
|
||||
**Files Changed**:
|
||||
- `src/services/sqlite/SessionStore.ts` (getSessionById method)
|
||||
|
||||
### v4.2.7
|
||||
**Breaking Changes**: None (patch version)
|
||||
|
||||
**Improvements**:
|
||||
- Enhanced data quality with consistent null handling
|
||||
- `extractField()` now returns null for empty/whitespace-only strings
|
||||
- Ensures database stores clean null values instead of empty strings
|
||||
- Improves query efficiency and data consistency
|
||||
|
||||
**Testing**:
|
||||
- Added comprehensive regression test suite (49 tests)
|
||||
- Tests v4.2.5 summary validation fixes (partial summaries preserved)
|
||||
- Tests v4.2.6 observation validation fixes (partial observations preserved)
|
||||
- Tests edge cases: missing fields, empty fields, whitespace, invalid types
|
||||
- Tests data integrity: concept filtering, type validation, field preservation
|
||||
- New test script: `npm run test:parser`
|
||||
- All 49 tests passing with 100% coverage of critical parser edge cases
|
||||
|
||||
**Code Quality**:
|
||||
- Removed unused `extractFileArray()` function (replaced by `extractArrayElements()`)
|
||||
- Improved function documentation with clearer descriptions
|
||||
- TypeScript diagnostics clean
|
||||
|
||||
**Technical Details**:
|
||||
- Updated `src/sdk/parser.ts:163-169` extractField function
|
||||
- Created `src/sdk/parser.test.ts` with comprehensive regression tests
|
||||
- Added `test:parser` script to package.json
|
||||
- All changes backward compatible with existing database schema
|
||||
|
||||
### v4.2.6
|
||||
**Breaking Changes**: None (patch version)
|
||||
|
||||
**Critical Bugfix**:
|
||||
- Fixed overly defensive observation validation that was blocking observations from being saved
|
||||
- Removed validation requiring title, subtitle, and narrative fields
|
||||
- Parser now NEVER skips observations - always saves them
|
||||
- Invalid or missing type defaults to "change" (generic catch-all type)
|
||||
- Prevents critical data loss - partial observations are better than no observations
|
||||
|
||||
**Impact**:
|
||||
- Before: Missing title, subtitle, OR narrative caused entire observation to be discarded
|
||||
- After: ALL observations preserved regardless of field completeness
|
||||
- Even partial observations contain valuable data: concepts, files_read, files_modified, facts
|
||||
- LLMs make mistakes - system must be resilient and save everything
|
||||
- Consistent with v4.2.5 summary fix - partial data is always better than no data
|
||||
|
||||
**Technical Details**:
|
||||
- Updated `src/sdk/parser.ts:52-67` to never skip observations
|
||||
- Uses "change" as fallback type for invalid/missing types (no schema change needed)
|
||||
- Updated ParsedObservation interface to allow null for title, subtitle, narrative
|
||||
- Database schema already supports nullable fields
|
||||
- Parser now matches database schema constraints exactly
|
||||
- Affects `parseObservations()` function used by worker service
|
||||
|
||||
### v4.2.5
|
||||
**Breaking Changes**: None (patch version)
|
||||
|
||||
**Critical Bugfix**:
|
||||
- Fixed overly defensive summary validation that was blocking summaries from being saved
|
||||
- Removed validation check that returned null when any required fields were missing
|
||||
- Summaries are now always saved when `<summary>` tags are present, even if fields are incomplete
|
||||
- Prevents critical data loss - partial summaries are better than no summaries
|
||||
- Database schema already supports null/empty values for all fields
|
||||
|
||||
**Impact**:
|
||||
- Before: Missing a single field (e.g., `next_steps`) would cause entire summary to be discarded
|
||||
- After: All summaries are preserved, maintaining session context even when incomplete
|
||||
- This fix ensures continuity of the memory compression system
|
||||
|
||||
**Technical Details**:
|
||||
- Updated `src/sdk/parser.ts:137-147` to remove blocking validation
|
||||
- Parser now returns ParsedSummary with whatever fields are available
|
||||
- Affects `parseSummary()` function used by worker service
|
||||
|
||||
### v4.2.4
|
||||
**Breaking Changes**: None (patch version)
|
||||
|
||||
**Improvements**:
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
# Experimental Release: Progressive Disclosure Context System
|
||||
|
||||
## 🧪 Branch: `feature/context-with-observations`
|
||||
|
||||
**Status:** Seeking user feedback before merging to main
|
||||
|
||||
**We'd love your testing and feedback!** This experimental branch reimagines how Claude-Mem presents context at session startup, using a progressive disclosure approach that could significantly improve Claude's ability to leverage past learnings.
|
||||
|
||||
---
|
||||
|
||||
## What is Progressive Disclosure?
|
||||
|
||||
Progressive disclosure is a **layered memory retrieval system** inspired by how humans remember information:
|
||||
|
||||
### Layer 1: Index (The "Table of Contents")
|
||||
**Frontloaded at session start** - Claude sees:
|
||||
- **What exists**: Titles of all recent observations and session summaries
|
||||
- **Retrieval cost**: Token counts for each observation
|
||||
- **Priority signals**: Type indicators (🔴 critical gotcha, 🟤 architectural decision, 🔵 explanatory)
|
||||
|
||||
### Layer 2: Details (On-Demand Retrieval)
|
||||
**Retrieved via MCP search** - Claude fetches:
|
||||
- Full observation narratives when deeper context is needed
|
||||
- Search by concept, file path, type, or keywords
|
||||
- Only loads what's relevant to the current task
|
||||
|
||||
### Layer 3: Perfect Recall (Source of Truth)
|
||||
**Direct code access** - When needed:
|
||||
- Read actual source files for implementation details
|
||||
- Access original transcripts for exact quotes
|
||||
- Full context without compression artifacts
|
||||
|
||||
---
|
||||
|
||||
## The Problem This Solves
|
||||
|
||||
### Current Version (v4.2.x) Limitation
|
||||
|
||||
The current context hook shows **only session summaries** at startup:
|
||||
|
||||
```markdown
|
||||
**Session #312**: Put date/time at end of session titles
|
||||
Completed: Added date/time to session list with proper formatting
|
||||
Next Steps: Test edge cases with long dates
|
||||
```
|
||||
|
||||
**Strengths:**
|
||||
- ✅ Minimal token overhead (~800 tokens)
|
||||
- ✅ Clean, readable summaries
|
||||
|
||||
**Weaknesses:**
|
||||
- ❌ Claude doesn't know **what** detailed observations exist
|
||||
- ❌ Can't make informed decisions about whether to search vs read code
|
||||
- ❌ Often re-reads code to understand decisions that were already documented
|
||||
|
||||
### Experimental Version Enhancement
|
||||
|
||||
The experimental hook shows an **observation index** alongside session summaries:
|
||||
|
||||
```markdown
|
||||
**src/hooks/context.ts**
|
||||
| ID | Time | T | Title | Tokens |
|
||||
|----|------|---|-------|--------|
|
||||
| #2332 | 1:07 AM | 🔴 | Critical Bugfix: Session ID NULL Constraint | ~201 |
|
||||
| #2340 | 1:10 AM | 🟠 | Remove Redundant Summary Section | ~280 |
|
||||
| #2344 | 1:34 AM | 🔵 | Added progressive disclosure usage instructions | ~149 |
|
||||
```
|
||||
|
||||
**Benefits:**
|
||||
- ✅ Claude knows **what** learnings exist (titles/types)
|
||||
- ✅ Token counts inform **cost-benefit** decisions (fetch ~200 tokens vs re-read 2000-line file)
|
||||
- ✅ Progressive disclosure instructions **teach Claude** how to use the system
|
||||
- ✅ Type indicators help prioritize (critical gotchas > explanatory notes)
|
||||
|
||||
**Trade-offs:**
|
||||
- ⚠️ Higher initial token cost (~2,500 tokens vs ~800)
|
||||
- ⚠️ More visual noise in the context output
|
||||
- ❓ Unknown: Does this actually improve Claude's behavior enough to justify the cost?
|
||||
|
||||
---
|
||||
|
||||
## What's New in This Branch
|
||||
|
||||
### 1. Observation Index Display
|
||||
|
||||
Full table view of recent observations grouped by file:
|
||||
|
||||
```markdown
|
||||
### Oct 25, 2025
|
||||
|
||||
**src/hooks/context.ts**
|
||||
| ID | Time | T | Title | Tokens |
|
||||
|----|------|---|-------|--------|
|
||||
| #2296 | 12:12 AM | 🟢 | Session summaries now display date and time | ~141 |
|
||||
| #2298 | 12:44 AM | 🔵 | Timeline rendering refactored | ~231 |
|
||||
|
||||
**General**
|
||||
| ID | Time | T | Title | Tokens |
|
||||
|----|------|---|-------|--------|
|
||||
| #2301 | 12:50 AM | 🟢 | Development Task Breakdown Created | ~128 |
|
||||
```
|
||||
|
||||
### 2. Token Cost Metadata
|
||||
|
||||
Every observation shows estimated token count:
|
||||
- Helps Claude decide: "Is it worth fetching this 500-token explanation, or should I just read the code?"
|
||||
- Makes cost-benefit analysis explicit
|
||||
|
||||
### 3. Progressive Disclosure Instructions
|
||||
|
||||
New guidance section teaches Claude how to use the system:
|
||||
|
||||
```markdown
|
||||
💡 Progressive Disclosure: This index shows WHAT exists (titles) and retrieval COST (token counts).
|
||||
- Use MCP search tools to fetch full observation details on-demand (Layer 2)
|
||||
- Prefer searching observations over re-reading code for past decisions and learnings
|
||||
- Critical types (🔴 gotcha, 🟤 decision, ⚖️ trade-off) often worth fetching immediately
|
||||
```
|
||||
|
||||
### 4. Type-Based Priority System
|
||||
|
||||
Observations categorized by importance:
|
||||
- 🔴 **gotcha** - Critical bugs/blockers (fetch immediately)
|
||||
- 🟤 **decision** - Architectural choices (high value)
|
||||
- ⚖️ **trade-off** - Design considerations (prevents re-debating)
|
||||
- 🟠 **why-it-exists** - Rationale documentation
|
||||
- 🟡 **problem-solution** - How issues were solved
|
||||
- 🟣 **discovery** - Important learnings
|
||||
- 🔵 **how-it-works** - Explanatory/educational
|
||||
- 🟢 **what-changed** - Implementation details
|
||||
|
||||
---
|
||||
|
||||
## Testing Instructions
|
||||
|
||||
### Option 1: Quick Test (No Installation)
|
||||
|
||||
```bash
|
||||
# Clone and checkout experimental branch
|
||||
git clone https://github.com/thedotmack/claude-mem.git
|
||||
cd claude-mem
|
||||
git checkout feature/context-with-observations
|
||||
|
||||
# Build the experimental version
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
# Navigate to YOUR project directory
|
||||
cd /path/to/your/project
|
||||
|
||||
# Run the experimental context hook with full path
|
||||
node /path/to/claude-mem/plugin/scripts/context-hook.js
|
||||
|
||||
# Example:
|
||||
# cd ~/my-app
|
||||
# node ~/Downloads/claude-mem/plugin/scripts/context-hook.js
|
||||
```
|
||||
|
||||
**Important:** The context hook reads from the current working directory (cwd). You must run it from your project's root folder to see context for that specific project.
|
||||
|
||||
This shows you the new context format without installing the plugin.
|
||||
|
||||
### Option 2: Full Testing (Install Locally)
|
||||
|
||||
If you're already using claude-mem and want to test the experimental version:
|
||||
|
||||
```bash
|
||||
# Navigate to your local claude-mem plugin directory
|
||||
cd ~/.claude/plugins/marketplaces/thedotmack
|
||||
|
||||
# Checkout experimental branch
|
||||
git fetch origin
|
||||
git checkout feature/context-with-observations
|
||||
|
||||
# Rebuild
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
# Restart Claude Code to see the new context injection
|
||||
```
|
||||
|
||||
**⚠️ Warning:** This will replace your current context hook. To revert:
|
||||
```bash
|
||||
git checkout main
|
||||
npm run build
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## What We Want to Know
|
||||
|
||||
Please test the experimental branch and share your feedback on these questions:
|
||||
|
||||
### 1. Behavioral Impact
|
||||
- ✅ **Does Claude use MCP search more effectively?**
|
||||
- Does it fetch observation details more often?
|
||||
- Does it make better decisions about when to search vs read code?
|
||||
|
||||
### 2. Token Cost Analysis
|
||||
- 💰 **Do token counts influence Claude's retrieval decisions?**
|
||||
- Does Claude reference the token counts when deciding whether to fetch?
|
||||
- Example: "This observation is 500 tokens, so I'll read the code instead"
|
||||
|
||||
### 3. Instruction Effectiveness
|
||||
- 📖 **Is the progressive disclosure guidance helpful or noisy?**
|
||||
- Does Claude seem to understand the layered retrieval concept?
|
||||
- Do the instructions clutter the context or improve clarity?
|
||||
|
||||
### 4. Efficiency Gains
|
||||
- 🚀 **Does it reduce redundant code reading?**
|
||||
- Does Claude fetch learnings instead of re-reading entire files?
|
||||
- Overall: Is it faster/smarter despite the higher initial token cost?
|
||||
|
||||
### 5. User Experience
|
||||
- 👤 **Is the observation table too cluttered?**
|
||||
- Does the table format help or hurt readability?
|
||||
- Would you prefer a different presentation?
|
||||
|
||||
---
|
||||
|
||||
## How to Provide Feedback
|
||||
|
||||
### 📣 GitHub Issues (Please Use This!)
|
||||
|
||||
**[→ Click here to open a new issue](https://github.com/thedotmack/claude-mem/issues/new)**
|
||||
|
||||
Add the label `feedback: progressive-disclosure` and use this template:
|
||||
|
||||
```markdown
|
||||
## Progressive Disclosure Feedback
|
||||
|
||||
**Branch tested:** feature/context-with-observations
|
||||
**Test duration:** [e.g., 2 days, 10 sessions]
|
||||
**Project type:** [e.g., TypeScript library, React app, Python backend]
|
||||
|
||||
### What worked well:
|
||||
- [Your positive observations]
|
||||
|
||||
### What didn't work:
|
||||
- [Issues or concerns]
|
||||
|
||||
### Specific answers:
|
||||
1. **Claude's MCP search usage:** [Improved/Same/Worse]
|
||||
2. **Token count influence:** [Yes/No/Unclear]
|
||||
3. **Instructions helpful:** [Yes/No/Too verbose]
|
||||
4. **Code reading reduction:** [Yes/No/Hard to tell]
|
||||
5. **Overall impression:** [Worth merging/Needs work/Not useful]
|
||||
|
||||
### Additional notes:
|
||||
[Any other feedback, screenshots, or examples]
|
||||
```
|
||||
|
||||
**Why issues?** It keeps all feedback in one searchable place and lets other users see what's being discussed. Please don't hesitate to open an issue - all feedback is valuable, positive or negative!
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
Based on feedback, we'll decide:
|
||||
|
||||
### ✅ If Successful:
|
||||
- Merge to `main` branch
|
||||
- Release as v4.3.0
|
||||
- Make progressive disclosure the default
|
||||
- Potentially add verbosity settings (minimal/standard/detailed)
|
||||
|
||||
### ⚠️ If Mixed Results:
|
||||
- Make it opt-in via settings: `CLAUDE_MEM_VERBOSE_CONTEXT=true`
|
||||
- Default to current minimal approach
|
||||
- Allow users to choose their preference
|
||||
|
||||
### ❌ If Unsuccessful:
|
||||
- Keep as experimental branch
|
||||
- Continue iterating on the approach
|
||||
- May explore alternative presentation formats
|
||||
|
||||
---
|
||||
|
||||
## Technical Details
|
||||
|
||||
### Files Changed
|
||||
|
||||
- **src/hooks/context.ts** (lines 227-240)
|
||||
- Added progressive disclosure instructions
|
||||
- Enhanced observation table rendering
|
||||
- Token count display for each observation
|
||||
|
||||
### Token Cost Breakdown
|
||||
|
||||
**Current version (v4.2.x):**
|
||||
- Session summaries only: ~800 tokens
|
||||
- 3 sessions × ~250 tokens each
|
||||
- Minimal overhead
|
||||
|
||||
**Experimental version:**
|
||||
- Progressive disclosure instructions: ~150 tokens
|
||||
- Observation index: ~2,000 tokens
|
||||
- 50 observations × ~40 tokens per row
|
||||
- Session summaries: ~800 tokens
|
||||
- **Total: ~2,950 tokens**
|
||||
|
||||
**ROI Analysis:**
|
||||
- If this prevents even ONE 2,000-token file read per session, it pays for itself
|
||||
- If Claude makes smarter retrieval decisions, overall token usage could be lower
|
||||
|
||||
---
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
This experimental feature was inspired by:
|
||||
- Anthropic's "Effective context engineering for AI agents" (Sept 2025)
|
||||
- Claude Skills' progressive disclosure architecture (Oct 2025)
|
||||
- Real-world usage patterns from 200+ GitHub stars in 36 hours
|
||||
|
||||
Special thanks to our early adopters for pushing the boundaries of what's possible with persistent memory!
|
||||
|
||||
---
|
||||
|
||||
## Questions?
|
||||
|
||||
- 📖 **Docs:** [docs/](docs/)
|
||||
- 🐛 **Issues:** [GitHub Issues](https://github.com/thedotmack/claude-mem/issues)
|
||||
- 💬 **Discussion:** [GitHub Discussions](https://github.com/thedotmack/claude-mem/discussions)
|
||||
|
||||
---
|
||||
|
||||
**Happy Testing!** 🧪
|
||||
|
||||
We're excited to hear what you discover with progressive disclosure. This could be a game-changer for how Claude leverages long-term memory, but we need your real-world testing to validate the approach.
|
||||
|
||||
— Alex Newman ([@thedotmack](https://github.com/thedotmack))
|
||||
@@ -0,0 +1,83 @@
|
||||
# 🧪 Experimental: Progressive Disclosure Context System
|
||||
|
||||
> **We'd love your feedback!** Test the new context injection approach and share your experience.
|
||||
|
||||
## What is Progressive Disclosure?
|
||||
|
||||
A **layered memory retrieval system** that shows Claude:
|
||||
1. **Index** (frontloaded): What observations exist + token costs
|
||||
2. **Details** (on-demand): Full narratives via MCP search
|
||||
3. **Perfect recall**: Source code when needed
|
||||
|
||||
**The idea:** Instead of hiding observations completely, show an index so Claude can make informed decisions about what to fetch.
|
||||
|
||||
## Try It Out
|
||||
|
||||
```bash
|
||||
# Clone and build experimental version
|
||||
git clone https://github.com/thedotmack/claude-mem.git
|
||||
cd claude-mem
|
||||
git checkout feature/context-with-observations
|
||||
npm install && npm run build
|
||||
|
||||
# Navigate to YOUR project and run the hook
|
||||
cd /path/to/your/project
|
||||
node /path/to/claude-mem/plugin/scripts/context-hook.js
|
||||
```
|
||||
|
||||
**Important:** Run from your project's root directory to see context for that project.
|
||||
|
||||
## What's Different?
|
||||
|
||||
**Current (v4.2.x):** Session summaries only (~800 tokens)
|
||||
```markdown
|
||||
Session #312: Put date/time at end of session titles
|
||||
Completed: Added formatting
|
||||
Next: Test edge cases
|
||||
```
|
||||
|
||||
**Experimental:** Observation index + summaries (~2,500 tokens)
|
||||
```markdown
|
||||
**src/hooks/context.ts**
|
||||
| ID | Time | T | Title | Tokens |
|
||||
|----|------|---|-------|--------|
|
||||
| #2332 | 1:07 AM | 🔴 | Critical Bugfix: Session ID NULL | ~201 |
|
||||
| #2340 | 1:10 AM | 🟠 | Remove Redundant Summary Section | ~280 |
|
||||
```
|
||||
|
||||
Now Claude knows:
|
||||
- What learnings exist (without loading them)
|
||||
- Cost to fetch details (~200 tokens)
|
||||
- Priority (🔴 critical vs 🔵 informational)
|
||||
|
||||
## We Want Your Feedback
|
||||
|
||||
Test the experimental branch and tell us:
|
||||
|
||||
✅ **Does Claude use MCP search more effectively?**
|
||||
💰 **Do token counts influence retrieval decisions?**
|
||||
📖 **Are the instructions helpful or noisy?**
|
||||
🚀 **Does it reduce redundant code reading?**
|
||||
|
||||
### 📣 [Please Open a GitHub Issue](https://github.com/thedotmack/claude-mem/issues/new) With Your Experience!
|
||||
|
||||
Use the label `feedback: progressive-disclosure` - all feedback is valuable, positive or negative!
|
||||
|
||||
## Files Changed
|
||||
|
||||
- Updated `README.md` with experimental feature section
|
||||
- Enhanced `src/hooks/context.ts` with progressive disclosure instructions
|
||||
- New docs: `EXPERIMENTAL_RELEASE_NOTES.md` (full details)
|
||||
|
||||
## Next Steps
|
||||
|
||||
Based on your feedback:
|
||||
- ✅ **If successful:** Merge to main, release as v4.3.0
|
||||
- ⚠️ **If mixed:** Make opt-in via settings
|
||||
- ❌ **If unsuccessful:** Keep iterating as experimental
|
||||
|
||||
---
|
||||
|
||||
**Full details:** See [EXPERIMENTAL_RELEASE_NOTES.md](EXPERIMENTAL_RELEASE_NOTES.md)
|
||||
|
||||
**Questions?** Join the discussion or open an issue!
|
||||
@@ -17,7 +17,7 @@
|
||||
<img src="https://img.shields.io/badge/License-AGPL%203.0-blue.svg" alt="License">
|
||||
</a>
|
||||
<a href="package.json">
|
||||
<img src="https://img.shields.io/badge/version-4.2.3-green.svg" alt="Version">
|
||||
<img src="https://img.shields.io/badge/version-4.2.9-green.svg" alt="Version">
|
||||
</a>
|
||||
<a href="package.json">
|
||||
<img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg" alt="Node">
|
||||
@@ -40,6 +40,90 @@
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Experimental Feature: Progressive Disclosure Context
|
||||
|
||||
> **We'd love your feedback!** Test the new context injection system in `feature/context-with-observations`
|
||||
|
||||
### What is Progressive Disclosure?
|
||||
|
||||
Progressive disclosure is a layered approach to memory retrieval that mirrors how humans remember information:
|
||||
|
||||
**Layer 1: Index** (Frontloaded at session start)
|
||||
- **WHAT** exists: Observation titles and session summaries
|
||||
- **COST** of retrieval: Token counts for each observation
|
||||
- **TYPE** indicators: Critical (🔴 gotcha, 🟤 decision) vs informational (🔵 how-it-works)
|
||||
|
||||
**Layer 2: Details** (Retrieved on-demand via MCP search)
|
||||
- Full observation narratives when Claude needs deeper context
|
||||
- Search by concept, file, type, or keyword
|
||||
|
||||
**Layer 3: Perfect Recall** (Code/transcripts)
|
||||
- Source code when implementation details are needed
|
||||
- Original transcripts for exact quotes
|
||||
|
||||
### The Problem It Solves
|
||||
|
||||
**Current version** (v4.2.x): Shows only session-level summaries at startup
|
||||
- ✅ Minimal tokens (~800)
|
||||
- ❌ Claude doesn't know what detailed observations exist
|
||||
- ❌ Often re-reads code to understand past decisions
|
||||
|
||||
**Experimental version**: Shows observation index + session summaries
|
||||
- ✅ Claude sees WHAT learnings exist without loading full content
|
||||
- ✅ Token counts help Claude decide: "fetch details" vs "read code"
|
||||
- ✅ Progressive disclosure instructions teach Claude how to use the system
|
||||
- ⚠️ Higher token cost (~2,500) but potentially more efficient overall
|
||||
|
||||
### How It's Different
|
||||
|
||||
The experimental context hook displays observations in a **table format**:
|
||||
|
||||
```markdown
|
||||
**src/hooks/context.ts**
|
||||
| ID | Time | T | Title | Tokens |
|
||||
|----|------|---|-------|--------|
|
||||
| #2332 | 1:07 AM | 🔴 | Critical Bugfix: Session ID NULL Constraint | ~201 |
|
||||
| #2340 | 1:10 AM | 🟠 | Remove Redundant Summary Section | ~280 |
|
||||
```
|
||||
|
||||
Now Claude knows:
|
||||
- A critical bugfix exists about session IDs (~201 tokens to fetch)
|
||||
- A design decision exists about summary sections (~280 tokens)
|
||||
- Whether to use MCP search or just read the current code
|
||||
|
||||
### Try It Out
|
||||
|
||||
```bash
|
||||
# Clone and checkout the experimental branch
|
||||
git clone https://github.com/thedotmack/claude-mem.git
|
||||
cd claude-mem
|
||||
git checkout feature/context-with-observations
|
||||
|
||||
# Build the experimental version
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
# Test the new context hook (from YOUR project directory)
|
||||
cd /path/to/your/project
|
||||
node /path/to/claude-mem/plugin/scripts/context-hook.js
|
||||
|
||||
# Example:
|
||||
# cd ~/my-app
|
||||
# node ~/claude-mem/plugin/scripts/context-hook.js
|
||||
```
|
||||
|
||||
**Important:** Run the context hook from your project's root directory to see context specific to that project.
|
||||
|
||||
**We want to know:**
|
||||
- Does Claude use MCP search more effectively?
|
||||
- Do token counts influence retrieval decisions?
|
||||
- Is the progressive disclosure guidance helpful or noisy?
|
||||
- Does it reduce redundant code reading?
|
||||
|
||||
**📣 Share Your Feedback:** [Open a GitHub Issue](https://github.com/thedotmack/claude-mem/issues/new) with your experience! Tag it with `feedback: progressive-disclosure`
|
||||
|
||||
---
|
||||
|
||||
## Quick Start
|
||||
|
||||
Start a new Claude Code session in the terminal and enter the following commands:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+4
-22
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "claude-mem",
|
||||
"version": "4.2.4",
|
||||
"version": "4.2.9",
|
||||
"description": "Memory compression system for Claude Code - persist context across sessions",
|
||||
"keywords": [
|
||||
"claude",
|
||||
@@ -25,29 +25,20 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/thedotmack/claude-mem/issues"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node scripts/build-hooks.js",
|
||||
"build:hooks": "node scripts/build-hooks.js",
|
||||
"release": "node scripts/publish.js",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test": "node --test tests/",
|
||||
"test:parser": "npx tsx src/sdk/parser.test.ts",
|
||||
"test:context": "echo '{\"session_id\":\"test-'$(date +%s)'\",\"cwd\":\"'$(pwd)'\",\"source\":\"startup\"}' | node plugin/scripts/context-hook.js 2>/dev/null",
|
||||
"test:context:verbose": "echo '{\"session_id\":\"test-'$(date +%s)'\",\"cwd\":\"'$(pwd)'\",\"source\":\"startup\"}' | node plugin/scripts/context-hook.js",
|
||||
"import:xml": "tsx src/bin/import-xml-observations.ts",
|
||||
"cleanup:duplicates": "tsx src/bin/cleanup-duplicates.ts",
|
||||
"worker:start": "pm2 start ecosystem.config.cjs",
|
||||
"worker:stop": "pm2 stop claude-mem-worker",
|
||||
"worker:restart": "pm2 restart claude-mem-worker",
|
||||
"worker:logs": "pm2 logs claude-mem-worker",
|
||||
"worker:status": "pm2 status claude-mem-worker"
|
||||
"worker:logs": "pm2 logs claude-mem-worker"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anthropic-ai/claude-agent-sdk": "^0.1.23",
|
||||
@@ -66,14 +57,5 @@
|
||||
"esbuild": "^0.20.0",
|
||||
"tsx": "^4.20.6",
|
||||
"typescript": "^5.3.0"
|
||||
},
|
||||
"files": [
|
||||
"plugin",
|
||||
"src",
|
||||
"scripts",
|
||||
"docs",
|
||||
"ecosystem.config.cjs",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "claude-mem",
|
||||
"version": "4.2.4",
|
||||
"version": "4.2.9",
|
||||
"description": "Persistent memory system for Claude Code - seamlessly preserve context across sessions",
|
||||
"author": {
|
||||
"name": "Alex Newman"
|
||||
|
||||
@@ -223,7 +223,7 @@ ${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let s=Obje
|
||||
FROM observations
|
||||
WHERE sdk_session_id = ?
|
||||
`).all(e),r=new Set,n=new Set;for(let i of t){if(i.files_read)try{let a=JSON.parse(i.files_read);Array.isArray(a)&&a.forEach(d=>r.add(d))}catch{}if(i.files_modified)try{let a=JSON.parse(i.files_modified);Array.isArray(a)&&a.forEach(d=>n.add(d))}catch{}}return{filesRead:Array.from(r),filesModified:Array.from(n)}}getSessionById(e){return this.db.prepare(`
|
||||
SELECT id, sdk_session_id, project, user_prompt
|
||||
SELECT id, claude_session_id, sdk_session_id, project, user_prompt
|
||||
FROM sdk_sessions
|
||||
WHERE id = ?
|
||||
LIMIT 1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
import C from"path";import q from"better-sqlite3";import{join as E,dirname as W,basename as z}from"path";import{homedir as U}from"os";import{existsSync as te,mkdirSync as j}from"fs";import{fileURLToPath as H}from"url";function B(){return typeof __dirname<"u"?__dirname:W(H(import.meta.url))}var Y=B(),u=process.env.CLAUDE_MEM_DATA_DIR||E(U(),".claude-mem"),O=process.env.CLAUDE_CONFIG_DIR||E(U(),".claude"),ne=E(u,"archives"),ie=E(u,"logs"),oe=E(u,"trash"),ae=E(u,"backups"),de=E(u,"settings.json"),w=E(u,"claude-mem.db"),pe=E(O,"settings.json"),ce=E(O,"commands"),Ee=E(O,"CLAUDE.md");function $(p){j(p,{recursive:!0})}function M(){return E(Y,"..","..")}var L=(i=>(i[i.DEBUG=0]="DEBUG",i[i.INFO=1]="INFO",i[i.WARN=2]="WARN",i[i.ERROR=3]="ERROR",i[i.SILENT=4]="SILENT",i))(L||{}),A=class{level;useColor;constructor(){let e=process.env.CLAUDE_MEM_LOG_LEVEL?.toUpperCase()||"INFO";this.level=L[e]??1,this.useColor=process.stdout.isTTY??!1}correlationId(e,s){return`obs-${e}-${s}`}sessionId(e){return`session-${e}`}formatData(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return e.toString();if(typeof e=="object"){if(e instanceof Error)return this.level===0?`${e.message}
|
||||
${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let s=Object.keys(e);return s.length===0?"{}":s.length<=3?JSON.stringify(e):`{${s.length} keys: ${s.slice(0,3).join(", ")}...}`}return String(e)}formatTool(e,s){if(!s)return e;try{let t=typeof s=="string"?JSON.parse(s):s;if(e==="Bash"&&t.command){let r=t.command.length>50?t.command.substring(0,50)+"...":t.command;return`${e}(${r})`}if(e==="Read"&&t.file_path){let r=t.file_path.split("/").pop()||t.file_path;return`${e}(${r})`}if(e==="Edit"&&t.file_path){let r=t.file_path.split("/").pop()||t.file_path;return`${e}(${r})`}if(e==="Write"&&t.file_path){let r=t.file_path.split("/").pop()||t.file_path;return`${e}(${r})`}return e}catch{return e}}log(e,s,t,r,i){if(e<this.level)return;let d=new Date().toISOString().replace("T"," ").substring(0,23),n=L[e].padEnd(5),c=s.padEnd(6),_="";r?.correlationId?_=`[${r.correlationId}] `:r?.sessionId&&(_=`[session-${r.sessionId}] `);let a="";i!=null&&(this.level===0&&typeof i=="object"?a=`
|
||||
`+JSON.stringify(i,null,2):a=" "+this.formatData(i));let l="";if(r){let{sessionId:G,sdkSessionId:k,correlationId:R,...T}=r;Object.keys(T).length>0&&(l=` {${Object.entries(T).map(([g,b])=>`${g}=${b}`).join(", ")}}`)}let f=`[${d}] [${n}] [${c}] ${_}${t}${l}${a}`;e===3?console.error(f):console.log(f)}debug(e,s,t,r){this.log(0,e,s,t,r)}info(e,s,t,r){this.log(1,e,s,t,r)}warn(e,s,t,r){this.log(2,e,s,t,r)}error(e,s,t,r){this.log(3,e,s,t,r)}dataIn(e,s,t,r){this.info(e,`\u2192 ${s}`,t,r)}dataOut(e,s,t,r){this.info(e,`\u2190 ${s}`,t,r)}success(e,s,t,r){this.info(e,`\u2713 ${s}`,t,r)}failure(e,s,t,r){this.error(e,`\u2717 ${s}`,t,r)}timing(e,s,t,r){this.info(e,`\u23F1 ${s}`,r,{duration:`${t}ms`})}},X=new A;var N=class{db;constructor(){$(u),this.db=new q(w),this.db.pragma("journal_mode = WAL"),this.db.pragma("synchronous = NORMAL"),this.db.pragma("foreign_keys = ON"),this.initializeSchema(),this.ensureWorkerPortColumn(),this.ensurePromptTrackingColumns(),this.removeSessionSummariesUniqueConstraint(),this.addObservationHierarchicalFields(),this.makeObservationsTextNullable(),this.createUserPromptsTable()}initializeSchema(){try{this.db.exec(`
|
||||
import C from"path";import q from"better-sqlite3";import{join as _,dirname as W,basename as z}from"path";import{homedir as U}from"os";import{existsSync as te,mkdirSync as j}from"fs";import{fileURLToPath as H}from"url";function B(){return typeof __dirname<"u"?__dirname:W(H(import.meta.url))}var Y=B(),m=process.env.CLAUDE_MEM_DATA_DIR||_(U(),".claude-mem"),O=process.env.CLAUDE_CONFIG_DIR||_(U(),".claude"),ne=_(m,"archives"),ie=_(m,"logs"),oe=_(m,"trash"),ae=_(m,"backups"),de=_(m,"settings.json"),w=_(m,"claude-mem.db"),pe=_(O,"settings.json"),ce=_(O,"commands"),_e=_(O,"CLAUDE.md");function $(p){j(p,{recursive:!0})}function M(){return _(Y,"..","..")}var L=(i=>(i[i.DEBUG=0]="DEBUG",i[i.INFO=1]="INFO",i[i.WARN=2]="WARN",i[i.ERROR=3]="ERROR",i[i.SILENT=4]="SILENT",i))(L||{}),A=class{level;useColor;constructor(){let e=process.env.CLAUDE_MEM_LOG_LEVEL?.toUpperCase()||"INFO";this.level=L[e]??1,this.useColor=process.stdout.isTTY??!1}correlationId(e,s){return`obs-${e}-${s}`}sessionId(e){return`session-${e}`}formatData(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return e.toString();if(typeof e=="object"){if(e instanceof Error)return this.level===0?`${e.message}
|
||||
${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let s=Object.keys(e);return s.length===0?"{}":s.length<=3?JSON.stringify(e):`{${s.length} keys: ${s.slice(0,3).join(", ")}...}`}return String(e)}formatTool(e,s){if(!s)return e;try{let t=typeof s=="string"?JSON.parse(s):s;if(e==="Bash"&&t.command){let r=t.command.length>50?t.command.substring(0,50)+"...":t.command;return`${e}(${r})`}if(e==="Read"&&t.file_path){let r=t.file_path.split("/").pop()||t.file_path;return`${e}(${r})`}if(e==="Edit"&&t.file_path){let r=t.file_path.split("/").pop()||t.file_path;return`${e}(${r})`}if(e==="Write"&&t.file_path){let r=t.file_path.split("/").pop()||t.file_path;return`${e}(${r})`}return e}catch{return e}}log(e,s,t,r,i){if(e<this.level)return;let d=new Date().toISOString().replace("T"," ").substring(0,23),n=L[e].padEnd(5),c=s.padEnd(6),E="";r?.correlationId?E=`[${r.correlationId}] `:r?.sessionId&&(E=`[session-${r.sessionId}] `);let a="";i!=null&&(this.level===0&&typeof i=="object"?a=`
|
||||
`+JSON.stringify(i,null,2):a=" "+this.formatData(i));let l="";if(r){let{sessionId:G,sdkSessionId:k,correlationId:R,...T}=r;Object.keys(T).length>0&&(l=` {${Object.entries(T).map(([g,b])=>`${g}=${b}`).join(", ")}}`)}let f=`[${d}] [${n}] [${c}] ${E}${t}${l}${a}`;e===3?console.error(f):console.log(f)}debug(e,s,t,r){this.log(0,e,s,t,r)}info(e,s,t,r){this.log(1,e,s,t,r)}warn(e,s,t,r){this.log(2,e,s,t,r)}error(e,s,t,r){this.log(3,e,s,t,r)}dataIn(e,s,t,r){this.info(e,`\u2192 ${s}`,t,r)}dataOut(e,s,t,r){this.info(e,`\u2190 ${s}`,t,r)}success(e,s,t,r){this.info(e,`\u2713 ${s}`,t,r)}failure(e,s,t,r){this.error(e,`\u2717 ${s}`,t,r)}timing(e,s,t,r){this.info(e,`\u23F1 ${s}`,r,{duration:`${t}ms`})}},X=new A;var N=class{db;constructor(){$(m),this.db=new q(w),this.db.pragma("journal_mode = WAL"),this.db.pragma("synchronous = NORMAL"),this.db.pragma("foreign_keys = ON"),this.initializeSchema(),this.ensureWorkerPortColumn(),this.ensurePromptTrackingColumns(),this.removeSessionSummariesUniqueConstraint(),this.addObservationHierarchicalFields(),this.makeObservationsTextNullable(),this.createUserPromptsTable()}initializeSchema(){try{this.db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS schema_versions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
version INTEGER UNIQUE NOT NULL,
|
||||
@@ -223,7 +223,7 @@ ${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let s=Obje
|
||||
FROM observations
|
||||
WHERE sdk_session_id = ?
|
||||
`).all(e),r=new Set,i=new Set;for(let d of t){if(d.files_read)try{let n=JSON.parse(d.files_read);Array.isArray(n)&&n.forEach(c=>r.add(c))}catch{}if(d.files_modified)try{let n=JSON.parse(d.files_modified);Array.isArray(n)&&n.forEach(c=>i.add(c))}catch{}}return{filesRead:Array.from(r),filesModified:Array.from(i)}}getSessionById(e){return this.db.prepare(`
|
||||
SELECT id, sdk_session_id, project, user_prompt
|
||||
SELECT id, claude_session_id, sdk_session_id, project, user_prompt
|
||||
FROM sdk_sessions
|
||||
WHERE id = ?
|
||||
LIMIT 1
|
||||
@@ -322,9 +322,9 @@ ${o.gray}${"\u2500".repeat(60)}${o.reset}
|
||||
${o.dim}No previous summaries found for this project yet.${o.reset}
|
||||
`:`# [${r}] recent context
|
||||
|
||||
No previous summaries found for this project yet.`;let n=[];e?(n.push(""),n.push(`${o.bright}${o.cyan}\u{1F4DD} [${r}] recent context${o.reset}`),n.push(`${o.gray}${"\u2500".repeat(60)}${o.reset}`)):(n.push(`# [${r}] recent context`),n.push(""));let c=!0;for(let _=0;_<d.length;_++){let a=d[_],l=d.length-1-_,f=l===0,G=l>=1&&l<=3,k=l>3;if(c?e&&n.push(""):e?(n.push(`${o.gray}${"\u2500".repeat(60)}${o.reset}`),n.push("")):(n.push("---"),n.push("")),c=!1,k){a.request&&(e?(n.push(`${o.bright}${o.yellow}Request:${o.reset} ${a.request}`),n.push("")):(n.push(`**Request:** ${a.request}`),n.push("")));let T=new Date(a.created_at).toLocaleString();e?n.push(`${o.dim}Date: ${T}${o.reset}`):(n.push(`**Date:** ${T}`),n.push(""));continue}if(a.request&&(e?(n.push(`${o.bright}${o.yellow}Request:${o.reset} ${a.request}`),n.push("")):(n.push(`**Request:** ${a.request}`),n.push(""))),f&&a.learned&&(e?(n.push(`${o.bright}${o.blue}Learned:${o.reset} ${a.learned}`),n.push("")):(n.push(`**Learned:** ${a.learned}`),n.push(""))),a.completed&&(e?(n.push(`${o.bright}${o.green}Completed:${o.reset} ${a.completed}`),n.push("")):(n.push(`**Completed:** ${a.completed}`),n.push(""))),f&&a.next_steps&&(e?(n.push(`${o.bright}${o.magenta}Next Steps:${o.reset} ${a.next_steps}`),n.push("")):(n.push(`**Next Steps:** ${a.next_steps}`),n.push(""))),f){let T=i.db.prepare(`
|
||||
No previous summaries found for this project yet.`;let n=[];e?(n.push(""),n.push(`${o.bright}${o.cyan}\u{1F4DD} [${r}] recent context${o.reset}`),n.push(`${o.gray}${"\u2500".repeat(60)}${o.reset}`)):(n.push(`# [${r}] recent context`),n.push(""));let c=!0;for(let E=0;E<d.length;E++){let a=d[E],l=d.length-1-E,f=l===0,G=l>=1&&l<=3,k=l>3;if(c?e&&n.push(""):e?(n.push(`${o.gray}${"\u2500".repeat(60)}${o.reset}`),n.push("")):(n.push("---"),n.push("")),c=!1,k){a.request&&(e?(n.push(`${o.bright}${o.yellow}Request:${o.reset} ${a.request}`),n.push("")):(n.push(`**Request:** ${a.request}`),n.push("")));let T=new Date(a.created_at).toLocaleString();e?n.push(`${o.dim}Date: ${T}${o.reset}`):(n.push(`**Date:** ${T}`),n.push(""));continue}if(a.request&&(e?(n.push(`${o.bright}${o.yellow}Request:${o.reset} ${a.request}`),n.push("")):(n.push(`**Request:** ${a.request}`),n.push(""))),f&&a.learned&&(e?(n.push(`${o.bright}${o.blue}Learned:${o.reset} ${a.learned}`),n.push("")):(n.push(`**Learned:** ${a.learned}`),n.push(""))),a.completed&&(e?(n.push(`${o.bright}${o.green}Completed:${o.reset} ${a.completed}`),n.push("")):(n.push(`**Completed:** ${a.completed}`),n.push(""))),f&&a.next_steps&&(e?(n.push(`${o.bright}${o.magenta}Next Steps:${o.reset} ${a.next_steps}`),n.push("")):(n.push(`**Next Steps:** ${a.next_steps}`),n.push(""))),f){let T=i.db.prepare(`
|
||||
SELECT files_read, files_modified
|
||||
FROM observations
|
||||
WHERE sdk_session_id = ?
|
||||
`).all(a.sdk_session_id),h=new Set,g=new Set,b=m=>{try{return C.isAbsolute(m)?C.relative(t,m):m}catch{return m}};for(let m of T){if(m.files_read)try{let S=JSON.parse(m.files_read);Array.isArray(S)&&S.forEach(I=>h.add(b(I)))}catch{}if(m.files_modified)try{let S=JSON.parse(m.files_modified);Array.isArray(S)&&S.forEach(I=>g.add(b(I)))}catch{}}g.forEach(m=>h.delete(m)),h.size>0&&(e?n.push(`${o.dim}Files Read: ${Array.from(h).join(", ")}${o.reset}`):n.push(`**Files Read:** ${Array.from(h).join(", ")}`)),g.size>0&&(e?n.push(`${o.dim}Files Modified: ${Array.from(g).join(", ")}${o.reset}`):n.push(`**Files Modified:** ${Array.from(g).join(", ")}`))}let R=new Date(a.created_at).toLocaleString();e?n.push(`${o.dim}Date: ${R}${o.reset}`):n.push(`**Date:** ${R}`),e||n.push("")}return e&&(n.push(""),n.push(`${o.gray}${"\u2500".repeat(60)}${o.reset}`)),n.join(`
|
||||
`).all(a.sdk_session_id),h=new Set,g=new Set,b=u=>{try{return C.isAbsolute(u)?C.relative(t,u):u}catch{return u}};for(let u of T){if(u.files_read)try{let S=JSON.parse(u.files_read);Array.isArray(S)&&S.forEach(I=>h.add(b(I)))}catch{}if(u.files_modified)try{let S=JSON.parse(u.files_modified);Array.isArray(S)&&S.forEach(I=>g.add(b(I)))}catch{}}g.forEach(u=>h.delete(u)),h.size>0&&(e?n.push(`${o.dim}Files Read: ${Array.from(h).join(", ")}${o.reset}`):n.push(`**Files Read:** ${Array.from(h).join(", ")}`)),g.size>0&&(e?n.push(`${o.dim}Files Modified: ${Array.from(g).join(", ")}${o.reset}`):n.push(`**Files Modified:** ${Array.from(g).join(", ")}`))}let R=new Date(a.created_at).toLocaleString();e?n.push(`${o.dim}Date: ${R}${o.reset}`):n.push(`**Date:** ${R}`),e||n.push("")}return e&&(n.push(""),n.push(`${o.gray}${"\u2500".repeat(60)}${o.reset}`)),n.join(`
|
||||
`)}finally{i.close()}}import{stdin as x}from"process";try{let p=process.argv.includes("--index");if(x.isTTY){let e=D(void 0,!0,p);console.log(e),process.exit(0)}else{let e="";x.on("data",s=>e+=s),x.on("end",()=>{let s=e.trim()?JSON.parse(e):void 0,r={hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:D(s,!1,p)}};console.log(JSON.stringify(r)),process.exit(0)})}}catch(p){console.error(`[claude-mem context-hook error: ${p.message}]`),process.exit(0)}
|
||||
|
||||
@@ -223,7 +223,7 @@ ${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let s=Obje
|
||||
FROM observations
|
||||
WHERE sdk_session_id = ?
|
||||
`).all(e),r=new Set,o=new Set;for(let i of t){if(i.files_read)try{let a=JSON.parse(i.files_read);Array.isArray(a)&&a.forEach(d=>r.add(d))}catch{}if(i.files_modified)try{let a=JSON.parse(i.files_modified);Array.isArray(a)&&a.forEach(d=>o.add(d))}catch{}}return{filesRead:Array.from(r),filesModified:Array.from(o)}}getSessionById(e){return this.db.prepare(`
|
||||
SELECT id, sdk_session_id, project, user_prompt
|
||||
SELECT id, claude_session_id, sdk_session_id, project, user_prompt
|
||||
FROM sdk_sessions
|
||||
WHERE id = ?
|
||||
LIMIT 1
|
||||
|
||||
@@ -223,7 +223,7 @@ ${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let s=Obje
|
||||
FROM observations
|
||||
WHERE sdk_session_id = ?
|
||||
`).all(e),r=new Set,o=new Set;for(let i of t){if(i.files_read)try{let a=JSON.parse(i.files_read);Array.isArray(a)&&a.forEach(d=>r.add(d))}catch{}if(i.files_modified)try{let a=JSON.parse(i.files_modified);Array.isArray(a)&&a.forEach(d=>o.add(d))}catch{}}return{filesRead:Array.from(r),filesModified:Array.from(o)}}getSessionById(e){return this.db.prepare(`
|
||||
SELECT id, sdk_session_id, project, user_prompt
|
||||
SELECT id, claude_session_id, sdk_session_id, project, user_prompt
|
||||
FROM sdk_sessions
|
||||
WHERE id = ?
|
||||
LIMIT 1
|
||||
|
||||
@@ -365,7 +365,7 @@ ${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let t=Obje
|
||||
FROM observations
|
||||
WHERE sdk_session_id = ?
|
||||
`).all(e),r=new Set,n=new Set;for(let i of s){if(i.files_read)try{let o=JSON.parse(i.files_read);Array.isArray(o)&&o.forEach(c=>r.add(c))}catch{}if(i.files_modified)try{let o=JSON.parse(i.files_modified);Array.isArray(o)&&o.forEach(c=>n.add(c))}catch{}}return{filesRead:Array.from(r),filesModified:Array.from(n)}}getSessionById(e){return this.db.prepare(`
|
||||
SELECT id, sdk_session_id, project, user_prompt
|
||||
SELECT id, claude_session_id, sdk_session_id, project, user_prompt
|
||||
FROM sdk_sessions
|
||||
WHERE id = ?
|
||||
LIMIT 1
|
||||
|
||||
@@ -223,7 +223,7 @@ ${e.stack}`:e.message;if(Array.isArray(e))return`[${e.length} items]`;let s=Obje
|
||||
FROM observations
|
||||
WHERE sdk_session_id = ?
|
||||
`).all(e),r=new Set,o=new Set;for(let i of t){if(i.files_read)try{let a=JSON.parse(i.files_read);Array.isArray(a)&&a.forEach(d=>r.add(d))}catch{}if(i.files_modified)try{let a=JSON.parse(i.files_modified);Array.isArray(a)&&a.forEach(d=>o.add(d))}catch{}}return{filesRead:Array.from(r),filesModified:Array.from(o)}}getSessionById(e){return this.db.prepare(`
|
||||
SELECT id, sdk_session_id, project, user_prompt
|
||||
SELECT id, claude_session_id, sdk_session_id, project, user_prompt
|
||||
FROM sdk_sessions
|
||||
WHERE id = ?
|
||||
LIMIT 1
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,403 @@
|
||||
/**
|
||||
* Parser Regression Tests
|
||||
* Ensures v4.2.5 and v4.2.6 bugfixes remain stable
|
||||
*/
|
||||
|
||||
import { parseObservations, parseSummary } from './parser.js';
|
||||
|
||||
// ANSI color codes for output
|
||||
const GREEN = '\x1b[32m';
|
||||
const RED = '\x1b[31m';
|
||||
const YELLOW = '\x1b[33m';
|
||||
const RESET = '\x1b[0m';
|
||||
|
||||
let testsRun = 0;
|
||||
let testsPassed = 0;
|
||||
let testsFailed = 0;
|
||||
|
||||
function assert(condition: boolean, testName: string, errorMsg?: string): void {
|
||||
testsRun++;
|
||||
if (condition) {
|
||||
testsPassed++;
|
||||
console.log(`${GREEN}✓${RESET} ${testName}`);
|
||||
} else {
|
||||
testsFailed++;
|
||||
console.log(`${RED}✗${RESET} ${testName}`);
|
||||
if (errorMsg) {
|
||||
console.log(` ${RED}${errorMsg}${RESET}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function assertEqual<T>(actual: T, expected: T, testName: string): void {
|
||||
const isEqual = JSON.stringify(actual) === JSON.stringify(expected);
|
||||
if (!isEqual) {
|
||||
assert(false, testName, `Expected: ${JSON.stringify(expected)}, Got: ${JSON.stringify(actual)}`);
|
||||
} else {
|
||||
assert(true, testName);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('\n' + YELLOW + '='.repeat(60) + RESET);
|
||||
console.log(YELLOW + 'Parser Regression Tests (v4.2.5 & v4.2.6)' + RESET);
|
||||
console.log(YELLOW + '='.repeat(60) + RESET + '\n');
|
||||
|
||||
// ============================================================================
|
||||
// v4.2.6: Observation Parsing - NEVER Skip Observations
|
||||
// ============================================================================
|
||||
|
||||
console.log(YELLOW + '\nv4.2.6: Observation Validation Fixes' + RESET);
|
||||
console.log('─'.repeat(60) + '\n');
|
||||
|
||||
// Test 1: Observation with missing title should be saved
|
||||
const missingTitleXml = `
|
||||
<observation>
|
||||
<type>feature</type>
|
||||
<subtitle>Added new feature</subtitle>
|
||||
<narrative>Implemented the feature successfully</narrative>
|
||||
<facts>
|
||||
<fact>Created new file</fact>
|
||||
</facts>
|
||||
<concepts>
|
||||
<concept>authentication</concept>
|
||||
</concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified>
|
||||
<file>src/app.ts</file>
|
||||
</files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const missingTitleResult = parseObservations(missingTitleXml);
|
||||
assert(missingTitleResult.length === 1, 'Should parse observation with missing title');
|
||||
assert(missingTitleResult[0].title === null, 'Missing title should be null');
|
||||
assertEqual(missingTitleResult[0].type, 'feature', 'Should preserve type when title missing');
|
||||
|
||||
// Test 2: Observation with missing subtitle should be saved
|
||||
const missingSubtitleXml = `
|
||||
<observation>
|
||||
<type>bugfix</type>
|
||||
<title>Fixed critical bug</title>
|
||||
<narrative>Resolved the issue</narrative>
|
||||
<facts></facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const missingSubtitleResult = parseObservations(missingSubtitleXml);
|
||||
assert(missingSubtitleResult.length === 1, 'Should parse observation with missing subtitle');
|
||||
assert(missingSubtitleResult[0].subtitle === null, 'Missing subtitle should be null');
|
||||
assertEqual(missingSubtitleResult[0].title, 'Fixed critical bug', 'Should preserve title when subtitle missing');
|
||||
|
||||
// Test 3: Observation with missing narrative should be saved
|
||||
const missingNarrativeXml = `
|
||||
<observation>
|
||||
<type>refactor</type>
|
||||
<title>Code cleanup</title>
|
||||
<subtitle>Improved structure</subtitle>
|
||||
<facts>
|
||||
<fact>Removed dead code</fact>
|
||||
</facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const missingNarrativeResult = parseObservations(missingNarrativeXml);
|
||||
assert(missingNarrativeResult.length === 1, 'Should parse observation with missing narrative');
|
||||
assert(missingNarrativeResult[0].narrative === null, 'Missing narrative should be null');
|
||||
assertEqual(missingNarrativeResult[0].facts, ['Removed dead code'], 'Should preserve facts when narrative missing');
|
||||
|
||||
// Test 4: Observation with ALL fields missing (except type) should be saved
|
||||
const minimalObservationXml = `
|
||||
<observation>
|
||||
<type>change</type>
|
||||
<title></title>
|
||||
<subtitle></subtitle>
|
||||
<narrative></narrative>
|
||||
<facts></facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const minimalResult = parseObservations(minimalObservationXml);
|
||||
assert(minimalResult.length === 1, 'Should parse minimal observation with only type');
|
||||
assertEqual(minimalResult[0].type, 'change', 'Should preserve type for minimal observation');
|
||||
assert(minimalResult[0].title === null, 'Empty title should be null');
|
||||
assert(minimalResult[0].subtitle === null, 'Empty subtitle should be null');
|
||||
assert(minimalResult[0].narrative === null, 'Empty narrative should be null');
|
||||
|
||||
// Test 5: Observation with missing type should use "change" as fallback
|
||||
const missingTypeXml = `
|
||||
<observation>
|
||||
<title>Something happened</title>
|
||||
<subtitle>Details here</subtitle>
|
||||
<narrative>More info</narrative>
|
||||
<facts></facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const missingTypeResult = parseObservations(missingTypeXml);
|
||||
assert(missingTypeResult.length === 1, 'Should parse observation with missing type');
|
||||
assertEqual(missingTypeResult[0].type, 'change', 'Missing type should default to "change"');
|
||||
|
||||
// Test 6: Observation with invalid type should use "change" as fallback
|
||||
const invalidTypeXml = `
|
||||
<observation>
|
||||
<type>invalid_type_here</type>
|
||||
<title>Something happened</title>
|
||||
<subtitle>Details here</subtitle>
|
||||
<narrative>More info</narrative>
|
||||
<facts></facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const invalidTypeResult = parseObservations(invalidTypeXml);
|
||||
assert(invalidTypeResult.length === 1, 'Should parse observation with invalid type');
|
||||
assertEqual(invalidTypeResult[0].type, 'change', 'Invalid type should default to "change"');
|
||||
|
||||
// Test 7: Multiple observations with mixed completeness should all be saved
|
||||
const mixedObservationsXml = `
|
||||
<observation>
|
||||
<type>feature</type>
|
||||
<title>Full observation</title>
|
||||
<subtitle>Complete</subtitle>
|
||||
<narrative>All fields present</narrative>
|
||||
<facts><fact>Fact 1</fact></facts>
|
||||
<concepts><concept>concept1</concept></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
<observation>
|
||||
<type>bugfix</type>
|
||||
<subtitle>Only subtitle and type</subtitle>
|
||||
<facts></facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
<observation>
|
||||
<title>Only title, no type</title>
|
||||
<facts></facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const mixedResult = parseObservations(mixedObservationsXml);
|
||||
assertEqual(mixedResult.length, 3, 'Should parse all three observations regardless of completeness');
|
||||
assertEqual(mixedResult[0].type, 'feature', 'First observation should have correct type');
|
||||
assertEqual(mixedResult[1].type, 'bugfix', 'Second observation should have correct type');
|
||||
assertEqual(mixedResult[2].type, 'change', 'Third observation should default to "change"');
|
||||
|
||||
// ============================================================================
|
||||
// v4.2.5: Summary Parsing - NEVER Skip Summaries
|
||||
// ============================================================================
|
||||
|
||||
console.log(YELLOW + '\nv4.2.5: Summary Validation Fixes' + RESET);
|
||||
console.log('─'.repeat(60) + '\n');
|
||||
|
||||
// Test 8: Summary with missing request field should be saved
|
||||
const missingRequestXml = `
|
||||
<summary>
|
||||
<investigated>Looked into the codebase</investigated>
|
||||
<learned>Found the issue</learned>
|
||||
<completed>Fixed the bug</completed>
|
||||
<next_steps>Deploy to production</next_steps>
|
||||
</summary>
|
||||
`;
|
||||
|
||||
const missingRequestResult = parseSummary(missingRequestXml);
|
||||
assert(missingRequestResult !== null, 'Should parse summary with missing request');
|
||||
assert(missingRequestResult!.request === null, 'Missing request should be null');
|
||||
assertEqual(missingRequestResult!.investigated, 'Looked into the codebase', 'Should preserve other fields');
|
||||
|
||||
// Test 9: Summary with missing investigated field should be saved
|
||||
const missingInvestigatedXml = `
|
||||
<summary>
|
||||
<request>Fix the bug</request>
|
||||
<learned>Root cause identified</learned>
|
||||
<completed>Applied the fix</completed>
|
||||
<next_steps>Monitor production</next_steps>
|
||||
</summary>
|
||||
`;
|
||||
|
||||
const missingInvestigatedResult = parseSummary(missingInvestigatedXml);
|
||||
assert(missingInvestigatedResult !== null, 'Should parse summary with missing investigated');
|
||||
assert(missingInvestigatedResult!.investigated === null, 'Missing investigated should be null');
|
||||
|
||||
// Test 10: Summary with missing learned field should be saved
|
||||
const missingLearnedXml = `
|
||||
<summary>
|
||||
<request>Add new feature</request>
|
||||
<investigated>Reviewed the requirements</investigated>
|
||||
<completed>Implemented the feature</completed>
|
||||
<next_steps>Write tests</next_steps>
|
||||
</summary>
|
||||
`;
|
||||
|
||||
const missingLearnedResult = parseSummary(missingLearnedXml);
|
||||
assert(missingLearnedResult !== null, 'Should parse summary with missing learned');
|
||||
assert(missingLearnedResult!.learned === null, 'Missing learned should be null');
|
||||
|
||||
// Test 11: Summary with missing completed field should be saved
|
||||
const missingCompletedXml = `
|
||||
<summary>
|
||||
<request>Refactor code</request>
|
||||
<investigated>Analyzed the structure</investigated>
|
||||
<learned>Found improvement opportunities</learned>
|
||||
<next_steps>Continue refactoring</next_steps>
|
||||
</summary>
|
||||
`;
|
||||
|
||||
const missingCompletedResult = parseSummary(missingCompletedXml);
|
||||
assert(missingCompletedResult !== null, 'Should parse summary with missing completed');
|
||||
assert(missingCompletedResult!.completed === null, 'Missing completed should be null');
|
||||
|
||||
// Test 12: Summary with missing next_steps field should be saved
|
||||
const missingNextStepsXml = `
|
||||
<summary>
|
||||
<request>Review code</request>
|
||||
<investigated>Examined all files</investigated>
|
||||
<learned>Code quality is good</learned>
|
||||
<completed>Review complete</completed>
|
||||
</summary>
|
||||
`;
|
||||
|
||||
const missingNextStepsResult = parseSummary(missingNextStepsXml);
|
||||
assert(missingNextStepsResult !== null, 'Should parse summary with missing next_steps');
|
||||
assert(missingNextStepsResult!.next_steps === null, 'Missing next_steps should be null');
|
||||
|
||||
// Test 13: Summary with only notes field should be saved
|
||||
const onlyNotesXml = `
|
||||
<summary>
|
||||
<notes>Some random notes</notes>
|
||||
</summary>
|
||||
`;
|
||||
|
||||
const onlyNotesResult = parseSummary(onlyNotesXml);
|
||||
assert(onlyNotesResult !== null, 'Should parse summary with only notes field');
|
||||
assertEqual(onlyNotesResult!.notes, 'Some random notes', 'Should preserve notes field');
|
||||
|
||||
// Test 14: Completely empty summary should be saved
|
||||
const emptySummaryXml = `
|
||||
<summary>
|
||||
<request></request>
|
||||
<investigated></investigated>
|
||||
<learned></learned>
|
||||
<completed></completed>
|
||||
<next_steps></next_steps>
|
||||
</summary>
|
||||
`;
|
||||
|
||||
const emptySummaryResult = parseSummary(emptySummaryXml);
|
||||
assert(emptySummaryResult !== null, 'Should parse completely empty summary');
|
||||
assert(emptySummaryResult!.request === null, 'Empty request should be null');
|
||||
assert(emptySummaryResult!.investigated === null, 'Empty investigated should be null');
|
||||
|
||||
// Test 15: Summary with skip_summary should return null (valid use case)
|
||||
const skipSummaryXml = `
|
||||
<skip_summary reason="Not enough context yet" />
|
||||
`;
|
||||
|
||||
const skipSummaryResult = parseSummary(skipSummaryXml);
|
||||
assert(skipSummaryResult === null, 'Should return null for skip_summary directive');
|
||||
|
||||
// ============================================================================
|
||||
// Edge Cases & Data Integrity
|
||||
// ============================================================================
|
||||
|
||||
console.log(YELLOW + '\nEdge Cases & Data Integrity' + RESET);
|
||||
console.log('─'.repeat(60) + '\n');
|
||||
|
||||
// Test 16: Observation with whitespace-only fields should be null
|
||||
const whitespaceObservationXml = `
|
||||
<observation>
|
||||
<type>change</type>
|
||||
<title> </title>
|
||||
<subtitle>
|
||||
|
||||
</subtitle>
|
||||
<narrative></narrative>
|
||||
<facts></facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const whitespaceResult = parseObservations(whitespaceObservationXml);
|
||||
assert(whitespaceResult.length === 1, 'Should parse observation with whitespace fields');
|
||||
assert(whitespaceResult[0].title === null || whitespaceResult[0].title!.trim() === '', 'Whitespace title should be null or empty');
|
||||
|
||||
// Test 17: Observation with concepts including type should filter out type
|
||||
const conceptsWithTypeXml = `
|
||||
<observation>
|
||||
<type>feature</type>
|
||||
<title>New feature</title>
|
||||
<subtitle>Details</subtitle>
|
||||
<narrative>Description</narrative>
|
||||
<facts></facts>
|
||||
<concepts>
|
||||
<concept>feature</concept>
|
||||
<concept>authentication</concept>
|
||||
</concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
|
||||
const conceptsWithTypeResult = parseObservations(conceptsWithTypeXml);
|
||||
assert(conceptsWithTypeResult.length === 1, 'Should parse observation with type in concepts');
|
||||
assertEqual(conceptsWithTypeResult[0].concepts, ['authentication'], 'Should filter out type from concepts');
|
||||
|
||||
// Test 18: Observation with all valid types
|
||||
const validTypes = ['decision', 'bugfix', 'feature', 'refactor', 'discovery', 'change'];
|
||||
validTypes.forEach(type => {
|
||||
const typeXml = `
|
||||
<observation>
|
||||
<type>${type}</type>
|
||||
<title>Test</title>
|
||||
<subtitle>Test</subtitle>
|
||||
<narrative>Test</narrative>
|
||||
<facts></facts>
|
||||
<concepts></concepts>
|
||||
<files_read></files_read>
|
||||
<files_modified></files_modified>
|
||||
</observation>
|
||||
`;
|
||||
const result = parseObservations(typeXml);
|
||||
assertEqual(result[0].type, type, `Should accept valid type: ${type}`);
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// Results Summary
|
||||
// ============================================================================
|
||||
|
||||
console.log('\n' + YELLOW + '='.repeat(60) + RESET);
|
||||
console.log(YELLOW + 'Test Results Summary' + RESET);
|
||||
console.log(YELLOW + '='.repeat(60) + RESET + '\n');
|
||||
|
||||
console.log(`Total Tests: ${testsRun}`);
|
||||
console.log(`${GREEN}Passed: ${testsPassed}${RESET}`);
|
||||
console.log(`${RED}Failed: ${testsFailed}${RESET}`);
|
||||
|
||||
if (testsFailed > 0) {
|
||||
console.log(`\n${RED}❌ TESTS FAILED${RESET}\n`);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(`\n${GREEN}✅ ALL TESTS PASSED${RESET}\n`);
|
||||
process.exit(0);
|
||||
}
|
||||
+40
-61
@@ -7,10 +7,10 @@ import { logger } from '../utils/logger.js';
|
||||
|
||||
export interface ParsedObservation {
|
||||
type: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
title: string | null;
|
||||
subtitle: string | null;
|
||||
facts: string[];
|
||||
narrative: string;
|
||||
narrative: string | null;
|
||||
concepts: string[];
|
||||
files_read: string[];
|
||||
files_modified: string[];
|
||||
@@ -49,39 +49,39 @@ export function parseObservations(text: string, correlationId?: string): ParsedO
|
||||
const files_read = extractArrayElements(obsContent, 'files_read', 'file');
|
||||
const files_modified = extractArrayElements(obsContent, 'files_modified', 'file');
|
||||
|
||||
// Validate required fields
|
||||
if (!type || !title || !subtitle || !narrative) {
|
||||
logger.warn('PARSER', 'Observation missing required fields, skipping', {
|
||||
correlationId,
|
||||
hasType: !!type,
|
||||
hasTitle: !!title,
|
||||
hasSubtitle: !!subtitle,
|
||||
hasNarrative: !!narrative
|
||||
});
|
||||
continue;
|
||||
// NOTE FROM THEDOTMACK: ALWAYS save observations - never skip. 10/24/2025
|
||||
// All fields except type are nullable in schema
|
||||
// If type is missing or invalid, use "change" as catch-all fallback
|
||||
|
||||
// Determine final type
|
||||
let finalType = 'change'; // Default catch-all
|
||||
if (type) {
|
||||
const validTypes = ['bugfix', 'feature', 'refactor', 'change', 'discovery', 'decision'];
|
||||
if (validTypes.includes(type.trim())) {
|
||||
finalType = type.trim();
|
||||
} else {
|
||||
logger.warn('PARSER', `Invalid observation type: ${type}, using "change"`, { correlationId });
|
||||
}
|
||||
} else {
|
||||
logger.warn('PARSER', 'Observation missing type field, using "change"', { correlationId });
|
||||
}
|
||||
|
||||
// Validate type
|
||||
const validTypes = ['bugfix', 'feature', 'refactor', 'change', 'discovery', 'decision'];
|
||||
if (!validTypes.includes(type.trim())) {
|
||||
logger.warn('PARSER', `Invalid observation type: ${type}, skipping`, { correlationId });
|
||||
continue;
|
||||
}
|
||||
// All other fields are optional - save whatever we have
|
||||
|
||||
// Filter out type from concepts array (types and concepts are separate dimensions)
|
||||
const cleanedConcepts = concepts.filter(c => c !== type.trim());
|
||||
const cleanedConcepts = concepts.filter(c => c !== finalType);
|
||||
|
||||
if (cleanedConcepts.length !== concepts.length) {
|
||||
logger.warn('PARSER', 'Removed observation type from concepts array', {
|
||||
correlationId,
|
||||
type: type.trim(),
|
||||
type: finalType,
|
||||
originalConcepts: concepts,
|
||||
cleanedConcepts
|
||||
});
|
||||
}
|
||||
|
||||
observations.push({
|
||||
type: type.trim(),
|
||||
type: finalType,
|
||||
title,
|
||||
subtitle,
|
||||
facts,
|
||||
@@ -130,18 +130,21 @@ export function parseSummary(text: string, sessionId?: number): ParsedSummary |
|
||||
const next_steps = extractField(summaryContent, 'next_steps');
|
||||
const notes = extractField(summaryContent, 'notes'); // Optional
|
||||
|
||||
// NOTE FROM THEDOTMACK: 100% of the time we must SAVE the summary, even if fields are missing. 10/24/2025
|
||||
// NEVER DO THIS NONSENSE AGAIN.
|
||||
|
||||
// Validate required fields are present (notes is optional)
|
||||
if (!request || !investigated || !learned || !completed || !next_steps) {
|
||||
logger.warn('PARSER', 'Summary missing required fields', {
|
||||
sessionId,
|
||||
hasRequest: !!request,
|
||||
hasInvestigated: !!investigated,
|
||||
hasLearned: !!learned,
|
||||
hasCompleted: !!completed,
|
||||
hasNextSteps: !!next_steps
|
||||
});
|
||||
return null;
|
||||
}
|
||||
// if (!request || !investigated || !learned || !completed || !next_steps) {
|
||||
// logger.warn('PARSER', 'Summary missing required fields', {
|
||||
// sessionId,
|
||||
// hasRequest: !!request,
|
||||
// hasInvestigated: !!investigated,
|
||||
// hasLearned: !!learned,
|
||||
// hasCompleted: !!completed,
|
||||
// hasNextSteps: !!next_steps
|
||||
// });
|
||||
// return null;
|
||||
// }
|
||||
|
||||
return {
|
||||
request,
|
||||
@@ -155,43 +158,19 @@ export function parseSummary(text: string, sessionId?: number): ParsedSummary |
|
||||
|
||||
/**
|
||||
* Extract a simple field value from XML content
|
||||
* Returns null for missing or empty/whitespace-only fields
|
||||
*/
|
||||
function extractField(content: string, fieldName: string): string | null {
|
||||
const regex = new RegExp(`<${fieldName}>([^<]*)</${fieldName}>`);
|
||||
const match = regex.exec(content);
|
||||
return match ? match[1].trim() : null;
|
||||
}
|
||||
if (!match) return null;
|
||||
|
||||
/**
|
||||
* Extract file array from XML content
|
||||
* Handles both <file> children and empty tags
|
||||
*/
|
||||
function extractFileArray(content: string, arrayName: string): string[] {
|
||||
const files: string[] = [];
|
||||
|
||||
// Match the array block
|
||||
const arrayRegex = new RegExp(`<${arrayName}>(.*?)</${arrayName}>`, 's');
|
||||
const arrayMatch = arrayRegex.exec(content);
|
||||
|
||||
if (!arrayMatch) {
|
||||
return files;
|
||||
}
|
||||
|
||||
const arrayContent = arrayMatch[1];
|
||||
|
||||
// Extract individual <file> elements
|
||||
const fileRegex = /<file>([^<]+)<\/file>/g;
|
||||
let fileMatch;
|
||||
while ((fileMatch = fileRegex.exec(arrayContent)) !== null) {
|
||||
files.push(fileMatch[1].trim());
|
||||
}
|
||||
|
||||
return files;
|
||||
const trimmed = match[1].trim();
|
||||
return trimmed === '' ? null : trimmed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract array of elements from XML content
|
||||
* Generic version of extractFileArray that works with any element name
|
||||
*/
|
||||
function extractArrayElements(content: string, arrayName: string, elementName: string): string[] {
|
||||
const elements: string[] = [];
|
||||
|
||||
+7
-21
@@ -158,35 +158,21 @@ export function buildObservationPrompt(obs: Observation): string {
|
||||
export function buildSummaryPrompt(session: SDKSession): string {
|
||||
return `THIS REQUEST'S SUMMARY
|
||||
===============
|
||||
Think about the observations you just wrote for this request, and write a summary of what was done, what was learned, and what's next.
|
||||
Think about the last request, and write a summary of what was done, what was learned, and what's next.
|
||||
|
||||
IMPORTANT! DO NOT summarize the observation process itself - you are summarizing a DIFFERENT claude code session, not this one.
|
||||
|
||||
User's Original Request: ${session.user_prompt}
|
||||
|
||||
✅ GOOD - Describes deliverables:
|
||||
<request>Fix authentication timeout bug</request>
|
||||
<request>Add three-tier verbosity system to session summaries</request>
|
||||
<request>Deploy Kubernetes cluster with auto-scaling</request>
|
||||
|
||||
❌ BAD - Describes meta-operations (DO NOT DO THIS):
|
||||
<request>Process tool executions and store observations</request>
|
||||
<request>Analyze session data and generate summaries</request>
|
||||
<request>Track file modifications across sessions</request>
|
||||
|
||||
Output this XML:
|
||||
Respond in this XML format:
|
||||
<summary>
|
||||
<request>[What did the user request? Form a title that reflects the actual request: ${session.user_prompt}]</request>
|
||||
<investigated>[What was explored?]</investigated>
|
||||
<learned>[What was learned about how things work?]</learned>
|
||||
<completed>[What shipped? What does the system now do?]</completed>
|
||||
<investigated>[Was anything explored? What was it?]</investigated>
|
||||
<learned>[Did you learn anything? What was learned about how things work?]</learned>
|
||||
<completed>[Did you do any work? What shipped? What does the system now do?]</completed>
|
||||
<next_steps>[What are the next steps?]</next_steps>
|
||||
<notes>[Additional insights]</notes>
|
||||
</summary>
|
||||
|
||||
**Required fields**: request, investigated, learned, completed, next_steps
|
||||
**Optional fields**: notes
|
||||
|
||||
IMPORTANT: This is not the end of the session. You will receive more requests to process, and more tool usages to observe and record. The summary helps keep track of progress.
|
||||
`;
|
||||
}
|
||||
IMPORTANT: This is not the end of the session. You will receive more requests to process, and more tool usages to observe and record. The summary helps keep track of progress. Always write at least a minimal summary explaining where we are at currently, even if you didn't learn anything new or complete any work.`;
|
||||
}
|
||||
@@ -702,12 +702,13 @@ export class SessionStore {
|
||||
*/
|
||||
getSessionById(id: number): {
|
||||
id: number;
|
||||
claude_session_id: string;
|
||||
sdk_session_id: string | null;
|
||||
project: string;
|
||||
user_prompt: string;
|
||||
} | null {
|
||||
const stmt = this.db.prepare(`
|
||||
SELECT id, sdk_session_id, project, user_prompt
|
||||
SELECT id, claude_session_id, sdk_session_id, project, user_prompt
|
||||
FROM sdk_sessions
|
||||
WHERE id = ?
|
||||
LIMIT 1
|
||||
@@ -903,10 +904,10 @@ export class SessionStore {
|
||||
project: string,
|
||||
observation: {
|
||||
type: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
title: string | null;
|
||||
subtitle: string | null;
|
||||
facts: string[];
|
||||
narrative: string;
|
||||
narrative: string | null;
|
||||
concepts: string[];
|
||||
files_read: string[];
|
||||
files_modified: string[];
|
||||
|
||||
@@ -128,14 +128,13 @@ class WorkerService {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the real claude_session_id (which is the same as sdk_session_id now)
|
||||
const claudeSessionId = dbSession.sdk_session_id || `session-${sessionDbId}`;
|
||||
const claudeSessionId = dbSession.claude_session_id;
|
||||
|
||||
// Create session state
|
||||
const session: ActiveSession = {
|
||||
sessionDbId,
|
||||
claudeSessionId,
|
||||
sdkSessionId: dbSession.sdk_session_id || null, // Set from database since we set both fields now
|
||||
sdkSessionId: null,
|
||||
project,
|
||||
userPrompt,
|
||||
pendingMessages: [],
|
||||
@@ -180,19 +179,16 @@ class WorkerService {
|
||||
let session = this.sessions.get(sessionDbId);
|
||||
if (!session) {
|
||||
// Auto-create session if it doesn't exist (e.g., worker restarted)
|
||||
// Fetch real session ID from database
|
||||
const db = new SessionStore();
|
||||
const dbSession = db.getSessionById(sessionDbId);
|
||||
db.close();
|
||||
|
||||
const claudeSessionId = dbSession?.sdk_session_id || `session-${sessionDbId}`;
|
||||
|
||||
session = {
|
||||
sessionDbId,
|
||||
claudeSessionId,
|
||||
claudeSessionId: dbSession!.claude_session_id,
|
||||
sdkSessionId: null,
|
||||
project: dbSession?.project || '',
|
||||
userPrompt: dbSession?.user_prompt || '',
|
||||
project: dbSession!.project,
|
||||
userPrompt: dbSession!.user_prompt,
|
||||
pendingMessages: [],
|
||||
abortController: new AbortController(),
|
||||
generatorPromise: null,
|
||||
@@ -244,19 +240,16 @@ class WorkerService {
|
||||
let session = this.sessions.get(sessionDbId);
|
||||
if (!session) {
|
||||
// Auto-create session if it doesn't exist (e.g., worker restarted)
|
||||
// Fetch real session ID from database
|
||||
const db = new SessionStore();
|
||||
const dbSession = db.getSessionById(sessionDbId);
|
||||
db.close();
|
||||
|
||||
const claudeSessionId = dbSession?.sdk_session_id || `session-${sessionDbId}`;
|
||||
|
||||
session = {
|
||||
sessionDbId,
|
||||
claudeSessionId,
|
||||
claudeSessionId: dbSession!.claude_session_id,
|
||||
sdkSessionId: null,
|
||||
project: dbSession?.project || '',
|
||||
userPrompt: dbSession?.user_prompt || '',
|
||||
project: dbSession!.project,
|
||||
userPrompt: dbSession!.user_prompt,
|
||||
pendingMessages: [],
|
||||
abortController: new AbortController(),
|
||||
generatorPromise: null,
|
||||
@@ -366,26 +359,8 @@ class WorkerService {
|
||||
});
|
||||
|
||||
for await (const message of queryResult) {
|
||||
// Handle system init message
|
||||
if (message.type === 'system' && message.subtype === 'init') {
|
||||
const systemMsg = message as SDKSystemMessage;
|
||||
if (systemMsg.session_id) {
|
||||
// Update in database first, check if it succeeded
|
||||
const db = new SessionStore();
|
||||
const updated = db.updateSDKSessionId(session.sessionDbId, systemMsg.session_id);
|
||||
db.close();
|
||||
|
||||
if (updated) {
|
||||
logger.success('SDK', 'Session initialized', {
|
||||
sessionId: session.sessionDbId,
|
||||
sdkSessionId: systemMsg.session_id
|
||||
});
|
||||
session.sdkSessionId = systemMsg.session_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Handle assistant messages
|
||||
else if (message.type === 'assistant') {
|
||||
if (message.type === 'assistant') {
|
||||
const content = message.message.content;
|
||||
const textContent = Array.isArray(content)
|
||||
? content.filter((c: any) => c.type === 'text').map((c: any) => c.text).join('\n')
|
||||
@@ -471,28 +446,26 @@ class WorkerService {
|
||||
session.lastPromptNumber = message.prompt_number;
|
||||
|
||||
const db = new SessionStore();
|
||||
const dbSession = db.getSessionById(session.sessionDbId) as SDKSession | undefined;
|
||||
const dbSession = db.getSessionById(session.sessionDbId) as SDKSession;
|
||||
db.close();
|
||||
|
||||
if (dbSession) {
|
||||
const summarizePrompt = buildSummaryPrompt(dbSession);
|
||||
const summarizePrompt = buildSummaryPrompt(dbSession);
|
||||
|
||||
logger.dataIn('SDK', `Summary prompt sent (${summarizePrompt.length} chars)`, {
|
||||
sessionId: session.sessionDbId,
|
||||
promptNumber: message.prompt_number
|
||||
});
|
||||
logger.debug('SDK', 'Full summary prompt', { sessionId: session.sessionDbId }, summarizePrompt);
|
||||
logger.dataIn('SDK', `Summary prompt sent (${summarizePrompt.length} chars)`, {
|
||||
sessionId: session.sessionDbId,
|
||||
promptNumber: message.prompt_number
|
||||
});
|
||||
logger.debug('SDK', 'Full summary prompt', { sessionId: session.sessionDbId }, summarizePrompt);
|
||||
|
||||
yield {
|
||||
type: 'user',
|
||||
session_id: session.claudeSessionId, // Use real session ID
|
||||
parent_tool_use_id: null,
|
||||
message: {
|
||||
role: 'user',
|
||||
content: summarizePrompt
|
||||
}
|
||||
};
|
||||
}
|
||||
yield {
|
||||
type: 'user',
|
||||
session_id: session.claudeSessionId,
|
||||
parent_tool_use_id: null,
|
||||
message: {
|
||||
role: 'user',
|
||||
content: summarizePrompt
|
||||
}
|
||||
};
|
||||
} else if (message.type === 'observation') {
|
||||
session.lastPromptNumber = message.prompt_number;
|
||||
|
||||
@@ -535,6 +508,13 @@ class WorkerService {
|
||||
private handleAgentMessage(session: ActiveSession, content: string, promptNumber: number): void {
|
||||
const correlationId = logger.correlationId(session.sessionDbId, session.observationCounter);
|
||||
|
||||
// Always log what we received for debugging
|
||||
logger.info('PARSER', `Processing response (${content.length} chars)`, {
|
||||
sessionId: session.sessionDbId,
|
||||
promptNumber,
|
||||
preview: content.substring(0, 200)
|
||||
});
|
||||
|
||||
// Parse observations
|
||||
const observations = parseObservations(content, correlationId);
|
||||
|
||||
@@ -548,26 +528,35 @@ class WorkerService {
|
||||
|
||||
const db = new SessionStore();
|
||||
for (const obs of observations) {
|
||||
if (session.sdkSessionId) {
|
||||
db.storeObservation(session.sdkSessionId, session.project, obs, promptNumber);
|
||||
logger.success('DB', 'Observation stored', {
|
||||
correlationId,
|
||||
type: obs.type,
|
||||
title: obs.title
|
||||
});
|
||||
}
|
||||
db.storeObservation(session.claudeSessionId, session.project, obs, promptNumber);
|
||||
logger.success('DB', 'Observation stored', {
|
||||
correlationId,
|
||||
type: obs.type,
|
||||
title: obs.title
|
||||
});
|
||||
}
|
||||
|
||||
// Parse summary
|
||||
// Parse summary and ALWAYS store it
|
||||
logger.info('PARSER', 'Looking for summary tags...', { sessionId: session.sessionDbId });
|
||||
const summary = parseSummary(content, session.sessionDbId);
|
||||
if (summary && session.sdkSessionId) {
|
||||
logger.info('PARSER', 'Summary parsed', {
|
||||
if (summary) {
|
||||
logger.success('PARSER', 'Summary parsed successfully!', {
|
||||
sessionId: session.sessionDbId,
|
||||
promptNumber
|
||||
promptNumber,
|
||||
hasRequest: !!summary.request,
|
||||
hasInvestigated: !!summary.investigated,
|
||||
hasLearned: !!summary.learned,
|
||||
hasCompleted: !!summary.completed,
|
||||
hasNextSteps: !!summary.next_steps
|
||||
});
|
||||
db.storeSummary(session.claudeSessionId, session.project, summary, promptNumber);
|
||||
logger.success('DB', '📝 SUMMARY STORED IN DATABASE', { sessionId: session.sessionDbId, promptNumber });
|
||||
} else {
|
||||
logger.warn('PARSER', 'NO SUMMARY TAGS FOUND in response', {
|
||||
sessionId: session.sessionDbId,
|
||||
promptNumber,
|
||||
contentSample: content.substring(0, 500)
|
||||
});
|
||||
|
||||
db.storeSummary(session.sdkSessionId, session.project, summary, promptNumber);
|
||||
logger.success('DB', 'Summary stored', { sessionId: session.sessionDbId });
|
||||
}
|
||||
|
||||
db.close();
|
||||
|
||||
Reference in New Issue
Block a user