Commit Graph

589 Commits

Author SHA1 Message Date
Alex Newman 4e7ed75fa9 Fix critical bugs in export/import feature (PR #225)
Addressed all 6 bugs identified in code reviews:

CRITICAL FIXES:
1. SessionStore.ts: Fixed concepts filter bug - removed empty params.push()
   that was breaking SQL parameter alignment (line 849)

2. import-memories.ts: Removed worker_port and prompt_counter fields from
   sdk_sessions insert to fix schema mismatch with fresh databases

3. export-memories.ts: Fixed hardcoded port - now reads from settings via
   SettingsDefaultsManager.loadFromFile()

HIGH PRIORITY:
4. export-memories.ts: Added database existence check with clear error
   message before opening database connection

5. export-memories.ts: Fixed variable shadowing - renamed local 'query'
   variable to 'sessionQuery' (line 90)

MEDIUM PRIORITY:
6. export-memories.ts: Improved type safety - added ObservationRecord,
   SdkSessionRecord, SessionSummaryRecord, UserPromptRecord interfaces

All fixes tested and verified:
- Export script successfully exports with project filtering
- Import script works on existing database with duplicate prevention
- Port configuration read from settings.json
- Type safety improvements prevent compile-time errors

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-10 20:15:26 -05:00
Alex Newman a8b84fa7b6 Update export script and rebuild with latest changes 2025-12-10 18:05:36 -05:00
Alex Newman 73be8f7a63 Fix export/import feature: JSON format and project filtering
Two critical fixes for the memory export/import feature:

1. **SearchManager empty results bug**: The /api/search endpoint
   with format=json now returns {observations: [], sessions: [],
   prompts: []} when no results are found, instead of the MCP
   protocol format. This fixes the export-memories script which
   expects consistent JSON structure regardless of result count.

2. **Project filtering support**: Updated SessionStore methods
   (getObservationsByIds, getSessionSummariesByIds, getUserPromptsByIds)
   to accept and apply project filter parameter. This enables
   proper project-based filtering during ChromaDB hybrid search
   result hydration.

Testing:
- Export with results:  50 observations exported
- Export with empty results:  Proper JSON structure
- Round-trip import:  Duplicate prevention working
- Project filtering:  claude-mem (51 obs) vs rad-mem (1 obs)

Fixes export/import feature blocking bugs.
2025-12-10 18:04:49 -05:00
Alex Newman fa93f2c1e2 Add export/import functionality and documentation for memory management 2025-12-10 17:39:55 -05:00
Alex Newman b39cf84730 Bump version to 7.0.10
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-10 17:22:56 -05:00
Alex Newman 772e235e92 Bump version to 7.0.9 and update CHANGELOG.md 2025-12-10 17:20:34 -05:00
Alex Newman 0986301e7a Update CHANGELOG.md for v7.0.9
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-10 16:29:51 -05:00
Alex Newman 822cf796e1 Bump version to 7.0.9
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
v7.0.9
2025-12-10 16:29:00 -05:00
7Sageer 53314d9c38 Fix: Return complete MCP response object instead of content array in SearchRoutes (#223)
All search route handlers were returning only result.content (array) instead
of the complete result object containing {content, isError}. This caused the
MCP server to receive an invalid response format, resulting in all search
tools hanging indefinitely.

Changes:
- Updated 14 route handlers to return full result object
- Ensures MCP protocol compatibility by providing expected response structure

Fixes search functionality for all claude-mem search tools including:
- Unified search, timeline, decisions, changes
- Observations, sessions, prompts search
- Concept, file, type filtering
- Recent context and timeline queries
2025-12-10 16:28:06 -05:00
Alex Newman 3a1ed0d299 Update CHANGELOG.md for v7.0.8 2025-12-10 14:26:45 -05:00
Alex Newman 8c589b6265 Bump version to 7.0.8 v7.0.8 2025-12-10 14:25:51 -05:00
Alex Newman 8bdec6abc0 Fix critical session persistence bug in new-hook (#224)
* Fix critical session persistence bug in new-hook

Restores the second POST call to /sessions/:sessionDbId/init that was
incorrectly removed as "duplicate" in the hooks refactor.

The two POST calls serve different purposes:
- POST /api/sessions/init: Creates DB session, saves prompt (no SDK agent)
- POST /sessions/:sessionDbId/init: Starts the SDK agent session

Without the second call, the SDK agent never started, causing:
- First prompts saved to DB but never processed
- Subsequent prompts queued but no agent running to consume them
- Each new prompt creating orphaned sessions instead of continuing

This fix restores proper session continuation across multiple prompts.

Fixes conversation fragmentation reported in production.

* updated agent-sdk

* Skip meta-observations for session-memory file operations

Added a check to skip meta-observations when file operations (Edit, Write, Read, NotebookEdit) are performed on session-memory files. If the file path includes 'session-memory', a debug log is generated and the response indicates that the observation was skipped.
2025-12-10 14:24:19 -05:00
Copilot 41fbb87aa0 Update documentation from claude-opus-4 to claude-opus-4-5 (#190)
* Initial plan

* Update all references from claude-opus-4 to claude-opus-4-5

Co-authored-by: thedotmack <683968+thedotmack@users.noreply.github.com>

* Use shorthand model names (haiku, sonnet, opus) throughout codebase

Updated model references to use shorthand names that automatically forward to latest versions:
- UI components (Sidebar, ContextSettingsModal)
- Documentation (configuration.mdx, worker-service.mdx)
- Build artifacts (viewer-bundle.js)

Shorthand names provide forward compatibility without requiring version-specific updates.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: thedotmack <683968+thedotmack@users.noreply.github.com>
Co-authored-by: Alex Newman <thedotmack@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 23:07:48 -05:00
Alex Newman fb9cccd350 Update CHANGELOG.md for v7.0.7
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 22:47:41 -05:00
Alex Newman 9387418707 Bump version to 7.0.7
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
v7.0.7
2025-12-09 22:46:50 -05:00
Alex Newman eaba21329c Refactor hooks codebase: reduce complexity and improve maintainability (#204)
* refactor: Clean up hook-response and new-hook files

- Removed 'PreCompact' hook type and associated logic from hook-response.ts for improved type safety.
- Deleted extensive architecture comments in new-hook.ts to streamline code readability.
- Simplified debug logging in new-hook.ts to reduce verbosity.
- Enhanced ensureWorkerRunning function in worker-utils.ts with a final health check before throwing errors.
- Added a new documentation file outlining the hooks cleanup process and future improvements.

* Refactor cleanup and user message hooks

- Updated cleanup-hook.js to improve error handling and remove unnecessary input checks.
- Simplified user-message-hook.js by removing time-sensitive announcements and streamlining output.
- Enhanced logging functionality in both hooks for better debugging and clarity.

* Refactor error handling in hooks to use centralized error handler

- Introduced `handleWorkerError` function in `src/shared/hook-error-handler.ts` to manage worker-related errors.
- Updated `context-hook.ts`, `new-hook.ts`, `save-hook.ts`, and `summary-hook.ts` to utilize the new error handler, simplifying error management and improving code readability.
- Removed repetitive error handling logic from individual hooks, ensuring consistent user-friendly messages for connection issues.

* Refactor user-message and summary hooks to utilize shared transcript parser; introduce hook exit codes

- Moved user message extraction logic to a new shared module `transcript-parser.ts` for better code reuse.
- Updated `summary-hook.ts` to use the new `extractLastMessage` function for retrieving user and assistant messages.
- Replaced direct exit code usage in `user-message-hook.ts` with constants from `hook-constants.ts` for improved readability and maintainability.
- Added `HOOK_EXIT_CODES` to `hook-constants.ts` to standardize exit codes across hooks.

* Refactor hook input interfaces to enforce required fields

- Updated `SessionStartInput`, `UserPromptSubmitInput`, `PostToolUseInput`, and `StopInput` interfaces to require `session_id`, `transcript_path`, and `cwd` fields, ensuring better type safety and clarity in hook inputs.
- Removed optional index signatures from these interfaces to prevent unintended properties and improve code maintainability.
- Adjusted related hook implementations to align with the new interface definitions.

* Refactor save-hook to remove tool skipping logic; enhance summary-hook to handle spinner stopping with error logging; update SessionRoutes to load skip tools from settings; add CLAUDE_MEM_SKIP_TOOLS to SettingsDefaultsManager for configurable tool exclusion.

* Document CLAUDE_MEM_SKIP_TOOLS setting in public docs

Added documentation for the new CLAUDE_MEM_SKIP_TOOLS configuration
setting in response to PR review feedback. Users can now discover and
customize which tools are excluded from observations.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 22:45:22 -05:00
Alex Newman 84c4d62812 Update CHANGELOG.md for v7.0.6
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 20:22:29 -05:00
Alex Newman 9e9ff20cba Bump version to 7.0.6
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
v7.0.6
2025-12-09 20:21:37 -05:00
Alex Newman bc28891bca Merge pull request #203 from CrystallDEV/fix/windows-terminal-spawning
fix(windows): hide terminal windows when spawning child processes
2025-12-09 20:19:17 -05:00
Alex Newman bafc86832c Update src/services/worker-service.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-09 20:19:06 -05:00
Alex Newman b985579959 Update scripts/smart-install.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-09 18:42:19 -05:00
CrystallDEV 5f36d2bf9a fix(windows): hide terminal windows when spawning child processes 2025-12-10 00:15:14 +01:00
Alex Newman 65e5411c21 Bump version to 7.0.5 in package.json 2025-12-09 17:29:46 -05:00
Alex Newman 7a22144069 Update CHANGELOG.md for v7.0.5
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 16:29:50 -05:00
Alex Newman 1360195390 Bump version to 7.0.5
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
v7.0.5
2025-12-09 16:28:01 -05:00
Alex Newman 6b38be29fb Merge pull request #201 from thedotmack/bugfix/settings-and-new-hook
Settings centralization and new-hook HTTP refactor
2025-12-09 16:25:58 -05:00
Alex Newman f992251c32 Refactor user-message-hook.js and worker-utils.ts for improved logging and Windows compatibility
- Enhanced logging functionality in user-message-hook.js to include better formatting and error handling.
- Updated worker-utils.ts to escape single quotes in PowerShell commands and added checks for global PM2 installation.
- Improved readability and maintainability of the code by restructuring and clarifying variable names.
2025-12-09 16:21:29 -05:00
Alex Newman c2015c4dfc Fix circular dependency crash in worker service
**Problem:**
Worker service crashed on startup with:
  TypeError: Cannot read properties of undefined (reading 'get')
  at new Wd (.../worker-service.cjs:52:131469)

**Root Cause:**
Circular dependency between SettingsDefaultsManager and logger:
  1. SettingsDefaultsManager imports logger
  2. logger imports SettingsDefaultsManager
  3. logger constructor calls SettingsDefaultsManager.get() at init time
  4. When CommonJS resolves the cycle, SettingsDefaultsManager is undefined

**Solution:**
Break the circular dependency by making logger lazy-load its configuration:
  - Change logger.level from initialized in constructor to lazy-loaded
  - Add getLevel() method that loads on first access
  - Update all level checks to use getLevel()

This allows SettingsDefaultsManager to import logger without triggering
the circular dependency, since logger no longer accesses SettingsDefaultsManager
during module initialization.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 16:13:10 -05:00
Alex Newman 005a80c540 Refactor SettingsDefaultsManager: Move to shared directory and update imports
- Moved SettingsDefaultsManager from worker/settings to shared directory.
- Updated all import paths across the codebase to reflect the new location.
- Removed early-settings.ts as its functionality is now handled by SettingsDefaultsManager.
- Adjusted logger and paths to utilize SettingsDefaultsManager for configuration values.
2025-12-09 15:29:17 -05:00
Alex Newman c3761a2204 Refactor silent debugging to happy path error handling
- Replaced instances of silentDebug with happy_path_error__with_fallback across multiple files to improve error logging and handling.
- Updated the utility function to provide clearer semantics for error handling when expected values are missing.
- Introduced a script to find potential silent failures in the codebase that may need to be addressed with the new error handling approach.
2025-12-09 15:09:44 -05:00
Alex Newman d957bff495 Remove postinstall script and update user message for first-time setup in hooks 2025-12-09 14:39:31 -05:00
Alex Newman c5ee27f001 Fix postinstall script path for first-run completion 2025-12-09 14:35:57 -05:00
Alex Newman d9f3798c90 Refactor user message hook for first-run detection, update Python version regex validation in settings routes, and simplify package commands directory retrieval 2025-12-09 14:33:23 -05:00
Alex Newman 1fb8df42b6 Refactor hook timeout settings to use centralized constants
- Introduced a new module `hook-constants.ts` to define timeout constants for various hooks.
- Updated `cleanup-hook.ts`, `context-hook.ts`, `save-hook.ts`, and `summary-hook.ts` to utilize the new `HOOK_TIMEOUTS.DEFAULT` for fetch timeouts instead of hardcoded values.
- Adjusted worker utility timeouts in `worker-utils.ts` to use constants from `hook-constants.ts`, improving maintainability and consistency across the codebase.
2025-12-09 14:25:53 -05:00
Alex Newman e09e64ade5 Refactor context and new hooks to use fetch API instead of execSync for HTTP requests; improve error handling for worker connection issues 2025-12-09 14:10:59 -05:00
Alex Newman 7cab32151e Enhance error handling and logging in early-settings and worker-utils
- Added silent debugging for settings file loading failures in early-settings.ts.
- Improved error logging in worker-utils.ts for health check and worker startup failures, including detailed error information and context.
2025-12-09 14:04:32 -05:00
Alex Newman a2f7a4dc5a Refactor new-hook to initialize sessions via HTTP and improve privacy handling
- Removed direct database operations in new-hook.ts and replaced them with an HTTP call to initialize sessions.
- Added error handling for HTTP requests and improved logging for session initialization.
- Updated SessionRoutes to handle new session initialization and privacy checks.
- Enhanced privacy tag stripping logic to prevent saving fully private prompts.
- Improved overall error handling and debugging messages throughout the session management process.
2025-12-09 13:43:11 -05:00
Alex Newman fc5c2d5e07 Refactor settings management to use ~/.claude-mem/settings.json
- Updated paths in troubleshooting documentation to reflect new settings file location.
- Modified diagnostics and reference files to read from ~/.claude-mem/settings.json.
- Introduced getWorkerPort utility for cleaner worker port retrieval.
- Enhanced ChromaSync and SDKAgent to load Python version and Claude path from settings.
- Updated SettingsRoutes to validate new settings: CLAUDE_MEM_LOG_LEVEL and CLAUDE_MEM_PYTHON_VERSION.
- Added early-settings module to load settings for logger and other early-stage modules.
- Adjusted logger to use early-loaded log level setting.
- Refactored paths to utilize early-loaded data directory setting.
2025-12-09 12:23:33 -05:00
Alex Newman b22adcca05 refactor: update permissions in settings.json and remove deprecated settings script 2025-12-09 11:44:09 -05:00
Alex Newman 2adc830c71 docs: update CHANGELOG.md for v7.0.4 2025-12-09 11:17:57 -05:00
Alex Newman e2c8f6b99e Merge pull request #196 from thedotmack/claude/release-7.0.4-windows-fixes-012Ny54FxUuyiNdJ28p1ohwd
chore: bump version to 7.0.4
v7.0.4
2025-12-09 10:32:49 -05:00
Claude 280608574b chore: bump version to 7.0.4
Comprehensive Windows bug fixes release. Thanks to @kat-bell for the
excellent contributions fixing Windows plugin installation and worker
startup issues.
2025-12-09 15:29:34 +00:00
Alex Newman 291f43d2c7 Merge pull request #195 from kat-bell/fix/windows-worker-startup-v2
fix(windows): Comprehensive fixes for Windows plugin installation
2025-12-09 10:24:22 -05:00
kat-bell d7dc29498c fix(cache): Add package.json to plugin directory for cache dependency resolution
The bundled hook scripts use `external: ['better-sqlite3']` during esbuild,
meaning the dependency must be resolved at runtime. When hooks run from the
cache directory (~/.claude/plugins/cache/thedotmack/claude-mem/X.X.X/),
they couldn't find better-sqlite3 because:

1. Cache directory had no package.json
2. smart-install.js was hardcoded to install in marketplace directory only

This fix:
- Adds plugin/package.json declaring runtime dependencies (better-sqlite3)
- Updates build-hooks.js to auto-generate plugin/package.json from main package.json
- Updates smart-install.js to detect execution context (cache vs marketplace)
  and install dependencies in the correct location

The script now detects if it's running from cache (via path pattern matching)
and installs dependencies there, where the hooks actually execute.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 05:27:26 -06:00
kat-bell 1f2e5f1a9c fix(windows): Comprehensive fixes for Windows plugin installation
This PR addresses issue #193 affecting Windows installations of claude-mem.

## Bug 1: Missing ecosystem.config.cjs in packaged plugin

**Problem**: The ecosystem.config.cjs file was not included in the plugin
package, causing PM2 to fail when trying to start the worker from cache.

**Fix**: Added `plugin/ecosystem.config.cjs` with correct path for packaged
structure (`./scripts/worker-service.cjs` instead of `./plugin/scripts/`).

## Bug 2: Incorrect MCP Server Path (src/services/worker-service.ts)

**Problem**: Path `__dirname, '..', '..', 'plugin', 'scripts', 'mcp-server.cjs'`
only worked in dev structure, failed in packaged plugin.

**Error produced**:
```
Error: Cannot find module 'C:\Users\...\claude-mem\plugin\scripts\mcp-server.cjs'
[ERROR] [SYSTEM] Background initialization failed MCP error -32000: Connection closed
```

**Fix**: Changed to `path.join(__dirname, 'mcp-server.cjs')` since mcp-server.cjs
is in the same directory as worker-service.cjs after bundling.

## Bug 3: Missing smart-install.js in plugin package

**Problem**: smart-install.js was referenced in hooks.json but not included
in the plugin/ directory for cache deployment.

**Fix**: Added `plugin/scripts/smart-install.js` that uses `createRequire()`
to resolve modules from MARKETPLACE_ROOT.

## Bug 4: hooks.json incorrect path

**Problem**: Referenced `/../scripts/smart-install.js` but CLAUDE_PLUGIN_ROOT
points to the plugin/ directory.

**Fix**: Changed to `/scripts/smart-install.js`.

## Bug 5: Windows Worker Startup - Visible Console Windows

**Problem**: PM2 ignores windowsHide option on Windows, opening visible
console windows when starting the worker service.

**Fix**: Use PowerShell `Start-Process -WindowStyle Hidden` on Windows while
keeping PM2 for Unix systems (src/shared/worker-utils.ts).

## Additional Improvements

- Increased worker startup timeouts for Windows (500ms health check, 1000ms
  wait between retries, 15 retries = 15s total vs previous 5s)
- Added `windowsHide: true` to root ecosystem.config.cjs for PM2

## Note on Assertion Failure

The Windows libuv assertion failure `!(handle->flags & UV_HANDLE_CLOSING)`
at `src\win\async.c:76` is a known upstream issue in Claude Code (Issue #7579),
triggered by fetch() calls on Windows. This is NOT caused by worker spawning
and cannot be fixed in claude-mem.

Tested on Windows 11 with Node.js v24.

Fixes #193

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 05:02:56 -06:00
Alex Newman 679a077f9b docs: update CHANGELOG.md for v7.0.3 2025-12-09 01:08:34 -05:00
Alex Newman f7a80e6abc chore: bump version to 7.0.3
Complete search-server to mcp-server rename

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
v7.0.3
2025-12-09 01:07:41 -05:00
Alex Newman 4321add69c refactor: rename search-server to mcp-server throughout codebase
- Updated all documentation references from search-server to mcp-server
- Removed legacy search-server.cjs file
- Updated debug log messages to use [mcp-server] prefix
- Updated build output references in docs

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 01:06:43 -05:00
Alex Newman 105b4ca70d docs: update CHANGELOG.md for v7.0.2 2025-12-09 01:03:47 -05:00
Alex Newman 06ba1cd92c chore: bump version to 7.0.2
Auto-start worker functionality improvements

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
v7.0.2
2025-12-09 01:02:55 -05:00