65 Commits

Author SHA1 Message Date
Alex Newman d7b9f68d80 Release v4.2.4: Enhanced summary prompt clarity
Improvements:
- Removed optional skip_summary functionality (summaries now always generated)
- Clarified that summaries are mid-session checkpoints, not session endings
- Improved request field instructions to better form descriptive titles
- Changed wording from "discovered" to "learned" for consistency

Technical changes:
- Updated src/sdk/prompts.ts summary prompt
- Removed "WHEN NOT TO SUMMARIZE" section
- Added clarifying footer text about ongoing sessions
- Updated built worker-service.cjs
- Bumped version to 4.2.4 in all metadata files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-24 20:50:31 -04:00
Alex Newman 0adbf38c39 fix: update getDirname function to support both ESM and CJS contexts 2025-10-23 23:03:48 -04:00
Alex Newman 15362d1aed Refactor getDirname function to only return __dirname for CJS context 2025-10-23 23:00:34 -04:00
Alex Newman c04e5c571c Merge pull request #16 from thedotmack/copilot/fix-plugin-hook-error
Fix Windows PowerShell compatibility for plugin hook installation
2025-10-23 20:12:25 -04:00
Alex Newman 66a69f3044 Merge pull request #11 from thedotmack/copilot/fix-fts5-injection-vulnerability
Security: Fix FTS5 injection vulnerability in search functions
2025-10-23 19:21:43 -04:00
copilot-swe-agent[bot] e50c6142bb Simplify Windows fix: use idempotent npm install instead of custom installer
Co-authored-by: thedotmack <683968+thedotmack@users.noreply.github.com>
2025-10-23 21:50:35 +00:00
copilot-swe-agent[bot] babb375955 Add cross-platform dependency installer for Windows compatibility
Co-authored-by: thedotmack <683968+thedotmack@users.noreply.github.com>
2025-10-23 21:25:49 +00:00
Alex Newman 37cd8b8328 fix: Improve summary prompt clarity and consistency in language 2025-10-23 14:21:31 -04:00
Alex Newman 33d2422faa Refactor summary prompt for clarity and emphasis on deliverables
- Changed the title of the summary prompt to "THIS REQUEST'S SUMMARY" for better context.
- Revised instructions to focus on summarizing what was built/fixed/deployed/configured, rather than the observation process.
- Clarified when not to summarize, emphasizing conversational requests and trivial inquiries.
- Updated examples to better illustrate good summary practices.
2025-10-23 14:08:42 -04:00
copilot-swe-agent[bot] dad3a104b4 Fix FTS5 injection vulnerability with proper escaping and comprehensive tests
Co-authored-by: thedotmack <683968+thedotmack@users.noreply.github.com>
2025-10-23 09:22:31 +00:00
Alex Newman f556546994 feat: Optimize context hook file listings to save tokens
Improvements to SessionStart context hook file display:

1. **Remove redundant files**: Files in "Modified" list are now excluded from "Read" list
   - Prevents duplication when a file was both read and modified
   - Reduces token usage by eliminating redundant information

2. **Use relative paths**: Convert absolute paths to project-relative paths
   - Example: /Users/alexnewman/Scripts/claude-mem/src/hooks/context.ts → src/hooks/context.ts
   - Significantly reduces token consumption in context injection
   - Makes file references more readable and portable

Implementation:
- Added toRelativePath() helper function to convert paths
- Added filesModifiedSet.forEach(file => filesReadSet.delete(file)) to remove duplicates
- Applied to both files_read and files_modified when building Sets

Impact: Reduces token usage in Tier 1 summaries (most recent session) where file lists are displayed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 17:23:44 -04:00
Alex Newman 2952b7fb8d feat: Add summary skip logic to prevent duplicate and trivial summaries
Added "WHEN NOT TO SUMMARIZE" section to buildSummaryPrompt that instructs the SDK to skip creating summaries for:
- Work already covered in previous prompts (prevents duplicates)
- Conversational banter with no deliverables
- Trivial requests (questions, status checks)
- Meta-discussions about memory system without shipped changes

Implementation:
- src/sdk/prompts.ts: Added WHEN NOT TO SUMMARIZE section with <skip_summary> output format
- src/sdk/parser.ts: Added skip_summary detection before parsing full summary XML
- src/sdk/parser.ts: Fixed observation type validation to include all 6 types (bugfix, feature, refactor, change, discovery, decision)

This should eliminate the duplicate summaries like the three "restore 6 types" summaries we saw for session d9137878.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 00:07:30 -04:00
Alex Newman 3cb003f4e4 fix(prompts): restore all 6 observation types for better search granularity
Restored full type system: bugfix, feature, refactor, change, discovery, decision.
This enables more precise search queries like "show all bugfixes in auth" vs generic "show all changes".

Also updated README to reflect current behavior (10 summaries with three-tier verbosity).

Changes:
- prompts.ts: Expanded type field from 3 to 6 types with clear definitions
- CLAUDE.md: Fixed context hook description (3 → 10 summaries)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 23:47:01 -04:00
Alex Newman 8b5e5efeb5 fix(prompts): prevent meta-referential descriptions in observations and summaries
Updated SDK prompts to distinguish between deliverables (what was built/shipped) vs meta-operations (what the memory system is doing). This prevents self-referential pollution like "Process tool executions" instead of actual coding tasks like "Fix authentication bug".

Changes:
- buildInitPrompt: Added deliverable-focused framing with contrastive examples
- buildSummaryPrompt: Injected user's original prompt + explicit examples
- Added verb guidance (implemented/fixed/deployed vs analyzed/tracked/stored)
- Added "NOW DOES" present-tense capability framing

Works across all project types: dev, DevOps, docs, infrastructure, research, config.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 23:42:12 -04:00
Alex Newman a57aba82a4 fix(context-hook): remove Learned from Tier 2
Tier 2 should only show Request + Completed + Date, not Learned.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 23:08:54 -04:00
Alex Newman 7b7a53ee19 feat(context-hook): simplify to 3-tier system with 10 sessions
New structure (10 sessions total):
- Tier 3 (oldest 6): Request + Date only
- Tier 2 (middle 3): Request + Learned + Completed + Date
- Tier 1 (most recent): Full verbosity (all fields)

This provides cleaner, more focused context with less redundancy.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 23:07:23 -04:00
Alex Newman e57bfc4187 feat(context-hook): implement tiered verbosity for session summaries
Introduces three-tier verbosity system to reduce redundancy and improve token efficiency:

Tier 1 (Most Recent - Position -1):
- Full verbosity with all fields shown
- Request, Learned, Completed, Next Steps, Files Read, Files Modified, Date

Tier 2 (Recent - Positions -2 to -5):
- Medium verbosity, skips Files Read (less actionable)
- Request, Learned, Completed, Next Steps, Files Modified, Date

Tier 3 (Older - Positions -6 to -30):
- Compact index with just Learned + citation link
- Format: Learned + [Details: claude-mem://session/{id}]
- Enables lazy-loading via MCP search tools

Changes:
- Increased LIMIT from 10 to 30 sessions
- Added position-based formatting logic in loop
- Token reduction: ~30% fewer tokens (~2,150 vs ~3,000)
- History expansion: 3x more sessions (30 vs 10)

Benefits:
- Reduced redundancy through natural information gradient
- More context breadth without token explosion
- MCP search becomes expansion mechanism for deeper dives
- Aligns with core philosophy: compression for efficiency, expansion on demand

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 23:01:57 -04:00
Alex Newman 3cfdd5fd65 feat(context-hook): simplify summary output by removing redundant session separators 2025-10-21 22:52:07 -04:00
Alex Newman 1a226b08f0 feat(context-hook): update session summaries query to use created_at_epoch for chronological display 2025-10-21 22:49:30 -04:00
Alex Newman 15b5176fe6 feat(context-hook): update session summaries query to order by created_at for chronological display 2025-10-21 22:49:01 -04:00
Alex Newman 418dc963b2 feat(context-hook): update session summaries query to retrieve more entries and display them chronologically 2025-10-21 22:47:42 -04:00
Alex Newman 2314362028 feat(WorkerService): set sdkSessionId from database during session initialization 2025-10-21 22:42:59 -04:00
Alex Newman f373b682dd feat(context-hook): enhance session summary output with color support and improved formatting 2025-10-21 22:40:13 -04:00
Alex Newman 1c25c3a7e7 Refactor contextHook to simplify recent summaries retrieval and output formatting
- Updated contextHook to query session_summaries directly instead of using sdk_sessions table.
- Removed unnecessary complexity in output formatting, focusing on recent summaries for the project.
- Enhanced file reading and modification tracking by parsing observations directly.
- Made the database connection public in SessionStore for easier access.
2025-10-21 22:36:41 -04:00
Alex Newman 3ca5e33b4a feat(worker-service): integrate real Claude Code session ID retrieval
- Added `claudeSessionId` to the `ActiveSession` interface to store the real Claude Code session ID.
- Updated session initialization to fetch the real Claude Code session ID from the database.
- Modified session creation logic to ensure the real session ID is used consistently throughout the worker service.
- Adjusted message generation to utilize the real session ID instead of a placeholder.
2025-10-21 22:20:31 -04:00
Alex Newman 3042de1093 feat(SessionStore): update SDK session creation to include sdk_session_id 2025-10-21 22:16:06 -04:00
Alex Newman f7f62ef3f3 feat(SessionStore): auto-create session records if missing
- Added functionality to automatically create a session record in the database if it does not exist when storing observations or session summaries.
- Updated `storeObservation` and `storeSummary` methods to include checks for existing session records and insert new records as needed.
- Added logging for auto-created session records for better traceability.
2025-10-21 22:13:13 -04:00
Alex Newman 726f167ebf feat: Implement full-text search for user prompts
- Added functionality to save raw user prompts for full-text search in the newHook function.
- Introduced new search endpoint 'search_user_prompts' to retrieve user prompts using FTS5.
- Created UserPromptRow and UserPromptSearchResult types for handling user prompt data.
- Implemented searchUserPrompts method in SessionSearch class to perform FTS5 queries.
- Created user_prompts table with FTS5 support and necessary triggers for data synchronization.
- Updated SessionStore to include methods for saving user prompts and managing the new table.
2025-10-21 22:02:06 -04:00
Alex Newman 635cc87462 fix: Auto-create sessions in worker when observations/summaries arrive
The worker was still returning 404 "Session not found" when trying to add
observations or summaries. This happened if:
- Worker restarted (sessions lost from memory)
- Race condition where observations arrive before /init
- Session continued after /exit

Changes:
- handleObservation: Auto-create session if not in memory map
- handleSummarize: Auto-create session if not in memory map

This completes the "no validation" philosophy: worker accepts any session_id
and auto-creates the session state if needed. Saves ALL data without blockage.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 21:46:50 -04:00
Alex Newman c27f07023c fix: Remove all session validation to prevent continuation errors after /exit
Root cause: Hooks provide session_id as the source of truth. We were adding
unnecessary validation (checking if sessions exist, checking status, etc.)
which caused 409 conflicts when continuing sessions after /exit.

Changes:
1. worker-service.ts: Removed 409 "Session already exists" check in handleInit
2. SessionStore.ts: Made createSDKSession idempotent using INSERT OR IGNORE
3. new-hook.ts: Simplified to just call createSDKSession - no findActiveSDKSession,
   no reactivateSession logic, no status management
4. save-hook.ts: Removed session validation, use fixed port instead of session.worker_port
5. summary-hook.ts: Removed session validation, use fixed port instead of session.worker_port

Philosophy: Hooks manage lifecycle, we just save data with whatever session_id
they give us. No validation, no status checks, no guessing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 21:44:58 -04:00
Alex Newman 562194612e Remove advanced search functionality from search-server and SessionSearch classes
- Deleted the advanced_search tool from the search-server.ts file, which combined full-text search with structured filters for observations and sessions.
- Removed the advancedSearch method from the SessionSearch class, which handled the logic for performing advanced searches using FTS5 and structured filters.
2025-10-21 19:12:36 -04:00
Alex Newman 02bce8a6e6 Enhance observation parsing and querying functionality
- Filter out observation type from concepts array in parseObservations function to ensure types and concepts are treated as separate dimensions. Added logging for removed types.
- Update prompts documentation to clarify that the observation type must not be included in the concepts array.
- Modify search-server to provide clearer guidance on result limits, emphasizing starting with smaller limits to avoid exceeding token limits.
- Refactor SessionSearch methods to accept options for limit, offset, and orderBy parameters, improving flexibility in querying observations by concept and type.
2025-10-21 19:01:11 -04:00
Alex Newman e9bcb7e9db Enhance search tips and tool descriptions for improved user guidance
- Updated the formatSearchTips function to emphasize the importance of using index format first for token efficiency.
- Revised descriptions for various search tools to include reminders about starting with index format and using full format only for specific items of interest.
- Clarified output format descriptions to recommend index format for initial searches.
2025-10-21 17:36:22 -04:00
Alex Newman ef572ec032 Refactor summary generation from session-level to request-level
Changed summary prompts to generate discrete per-request summaries instead of cumulative session summaries. This provides better chronological memory where each summary is a clean unit representing one request/response cycle.

Changes:
- Renamed buildFinalizePrompt() to buildSummaryPrompt() in src/sdk/prompts.ts
- Updated prompt text to focus on "THIS REQUEST" rather than "this session"
- Updated all import and function call sites in worker-service.ts and worker.ts
- Added IMPORTANT warning to emphasize request-level scope

Expected behavior: Each summary will now describe only what happened during that specific request, eliminating cumulative recaps.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 17:27:14 -04:00
Alex Newman 3cb99ab7f4 Swap 'Completed' and 'Learned' output formatting in context hook for clarity; adjust color coding accordingly 2025-10-21 16:41:27 -04:00
Alex Newman 20136121d8 Refactor context hook output formatting to improve readability; remove unnecessary line breaks 2025-10-21 16:40:14 -04:00
Alex Newman df0f3fd96c Enhance context hook output formatting and add file aggregation for sessions
- Updated contextHook to support colorized output for terminal and JSON format for hooks.
- Introduced ANSI color codes for improved readability in terminal output.
- Modified the output structure to include session details with color formatting.
- Added a new method in SessionStore to aggregate files read and modified from observations for a session.
- Improved error handling for JSON parsing of file data in the new method.
2025-10-21 16:37:16 -04:00
Alex Newman 32f45a1100 Add search tips and format options for observation and session search results
- Introduced `formatSearchTips` function to provide helpful search tips in the output.
- Added formatting options for search results, allowing users to choose between 'index' (titles/dates only) and 'full' (complete details).
- Updated handlers for observation and session search tools to accommodate the new format option.
- Enhanced result formatting to include date information and improved output structure.
2025-10-21 15:34:39 -04:00
Alex Newman 1ea692e0b0 chore: Update license information and add user settings manager script 2025-10-21 15:12:34 -04:00
Alex Newman d275715974 Release v4.1.0 - Graceful session cleanup and MCP search server restoration
### Changed
- Graceful session cleanup: Cleanup hook now marks sessions as completed instead of sending DELETE requests to worker
- Natural worker shutdown: Workers now finish pending operations (like summary generation) before terminating
- Restored MCP search server: Re-enabled full-text search capabilities from backup

### Fixed
- Session summaries no longer interrupted by aggressive cleanup during session end
- Workers can now complete final operations before shutdown

### Dependencies
- Updated @anthropic-ai/claude-agent-sdk to ^0.1.23
- Added @modelcontextprotocol/sdk ^1.20.1
- Added zod-to-json-schema ^3.24.6

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 01:07:56 -04:00
Alex Newman fd4684dcb3 Refactor search server to use Model Context Protocol SDK; update tool handling and response formatting
- Replaced `createSdkMcpServer` with `Server` from `@modelcontextprotocol/sdk/server/index.js`.
- Updated tool definitions to use structured input schemas with Zod.
- Enhanced response formatting for search results, combining multiple results into a single text response.
- Added new tools for advanced search and recent session context retrieval.
- Improved error handling and logging throughout the server.
2025-10-21 01:03:35 -04:00
Alex Newman c42444e06c Refactor cleanupHook to remove HTTP session deletion and mark session as completed in the database 2025-10-21 00:59:06 -04:00
Alex Newman cb2f2a0432 fix: Update command in SessionStart hook for correct node_modules path and remove package.json 2025-10-20 18:18:07 -04:00
Alex Newman 692bb07dfe fix: Add pm2 dependency to package.json for improved process management 2025-10-20 18:07:46 -04:00
Alex Newman 651989c423 refactor: Replace TypeScript bootstrap with bash dependency checks
Simplified dependency installation by moving from TypeScript runtime bootstrap to bash-based checks in plugin manifest. This reduces complexity and code size while maintaining the same functionality.

Changes:
- Added bash conditional dependency checks to all 5 hooks in hooks.json
- Check runs before each hook: [ ! -d "${CLAUDE_PLUGIN_ROOT}/scripts/node_modules" ] && cd "${CLAUDE_PLUGIN_ROOT}/scripts" && npm install || true
- Reverted all hook TypeScript files to use simple static imports (removed dynamic imports)
- Removed src/shared/bootstrap.ts (44 lines)
- Removed ensureDependencies() calls from all hook entry points

Benefits:
- Simpler architecture using native bash instead of TypeScript
- Net reduction of 157 lines of code
- No runtime overhead when dependencies already installed
- Uses plugin manifest's command hook feature as intended
- Faster and more efficient

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-20 17:01:24 -04:00
Alex Newman 9dd8b180ac fix: Use dynamic imports in hooks to fix better-sqlite3 loading
Changed all hook entry points to use dynamic imports after bootstrap runs. This ensures that better-sqlite3 is installed before Node.js attempts to resolve the import.

Changes:
- Modified src/bin/hooks/*.ts to call ensureDependencies() before dynamic import
- Moved from static `import { hook } from '...'` to `const { hook } = await import('...')`
- This delays module resolution until after npm install completes
- Bumped version to 4.0.6

The previous approach failed because static imports are resolved at module link time, before any runtime code (including ensureDependencies) executes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-20 16:54:28 -04:00
Alex Newman 6fb9570291 feat: Release v4.0.5 - Auto-install dependencies via bootstrap hooks
Fixed better-sqlite3 distribution by implementing self-bootstrapping hooks
that auto-install dependencies on first run. This eliminates the need for
users to have native compilation tools or manually install dependencies.

## Solution

Instead of bundling 25MB of better-sqlite3 binaries in git or requiring
manual npm install, hooks now bootstrap themselves on first execution:

1. Created `src/shared/bootstrap.ts` with `ensureDependencies()` function
2. Added bootstrap calls to all hook entry points (context, new, save, summary, cleanup)
3. Created `plugin/scripts/package.json` declaring better-sqlite3 dependency
4. Bootstrap checks if `node_modules` exists, runs `npm install` if missing
5. npm automatically downloads prebuilt better-sqlite3 binary for user's platform

## Changes

**Core Bootstrap System:**
- Added src/shared/bootstrap.ts: Auto-install dependencies using npm
- Modified all hooks (context, new, save, summary, cleanup) to call ensureDependencies()
- Created plugin/scripts/package.json with better-sqlite3 dependency

**Build & Distribution:**
- Removed node_modules copying logic from build script
- Build output is now compact (hooks + package.json, no binaries)
- Updated marketplace.json to point to GitHub for direct installation

**Documentation:**
- Updated README: GitHub Marketplace installation is now recommended method
- Installation instructions emphasize no compilation needed
- Version bumped to 4.0.5 throughout

## Benefits

-  No git bloat (repo stays small, no 25MB binaries committed)
-  No compilation needed (npm downloads prebuilt binaries)
-  Works on all platforms (npm handles platform-specific binaries)
-  Zero manual steps (hooks bootstrap themselves automatically)
-  Idempotent (skips install if dependencies already exist)

Installation now works via simple:
```
/plugin marketplace add https://github.com/thedotmack/claude-mem
/plugin install claude-mem
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-20 16:44:26 -04:00
Alex Newman f849a69506 fix: Move ensureWorkerRunning to start of hooks to prevent race condition
All hooks now call ensureWorkerRunning() BEFORE querying the database. This
ensures the worker's orphaned session cleanup runs before hooks check for
active sessions, preventing 404 errors when hooks try to use sessions that
don't exist in worker memory after a restart.

Hook order now:
1. ensureWorkerRunning() - starts worker, runs cleanup
2. Query DB - cleanup already marked orphaned sessions as failed
3. Use session - only valid sessions are processed

Fixed in:
- new-hook: Line 26, before DB queries
- save-hook: Line 37, before DB queries
- summary-hook: Line 24, before DB queries
- cleanup-hook: Line 50, before DB queries

This prevents the race condition where hooks would read session status before
cleanup ran, then get 404 from worker after cleanup marked sessions failed.
2025-10-19 02:01:11 -04:00
Alex Newman daf368e343 Refactor code structure for improved readability and maintainability 2025-10-19 01:45:51 -04:00
Alex Newman be0ab12789 Refactor worker startup logic to use PM2 with improved error handling
- Updated `new-hook.js` to streamline logging and session management.
- Enhanced database schema initialization and migration processes.
- Improved error handling for worker startup in `worker-utils.ts`, ensuring PM2 binary and ecosystem config existence before spawning.
- Added detailed error messages for missing dependencies and spawn failures.
2025-10-19 01:13:20 -04:00