Skip to content

fix(conversation-memory): silent first run with graceful CLI wrapper - #475

Merged
baleen37 merged 1 commit into
mainfrom
fix/conversation-memory-first-run
Feb 10, 2026
Merged

fix(conversation-memory): silent first run with graceful CLI wrapper#475
baleen37 merged 1 commit into
mainfrom
fix/conversation-memory-first-run

Conversation

@baleen37

@baleen37 baleen37 commented Feb 10, 2026

Copy link
Copy Markdown
Owner

Summary

Fix ERR_MODULE_NOT_FOUND error on first run by adding graceful CLI wrapper that checks for node_modules before importing better-sqlite3. When dependencies are missing, npm install runs asynchronously in background with silent exit.

Problem

The conversation-memory plugin threw a SessionStart:startup hook error on first run because the SessionStart hook directly called cli.mjs, which immediately imported better-sqlite3 before dependencies were installed. The plugin eventually recovered after auto-installing dependencies, but the initial error message was noisy and confusing.

Solution

Add cli-graceful.mjs wrapper that:

  1. Checks if node_modules exists before importing dependencies
  2. If missing, starts npm install in background (silent, detached)
  3. Exits immediately with code 0 (no error message)
  4. Next session: dependencies exist, inject works normally

Changes

  • src/cli-graceful.mjs (new) - checks deps, runs npm install in background
  • scripts/build.mjs - outputs cli-internal.mjs (bundled) + cli.mjs (wrapper copy)
  • hooks/ensure-deps.sh - updated to run silently in background
  • hooks/hooks.json - simplified (no longer needs ensure-deps hook)

Testing

First run (no deps): Silent exit, background npm install
Second run (with deps): Normal CLI operation
All BATS tests pass

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

Summary by CodeRabbit

  • Performance

    • Dependency installation now executes silently in the background, eliminating startup blocking and improving responsiveness.
    • Reduced hook timeout for quicker initialization.
  • Chores

    • Restructured build output and updated CLI initialization wrapper.

Add cli-graceful.mjs wrapper that checks node_modules before importing
better-sqlite3. On first run without dependencies, npm install runs
asynchronously in background with silent exit. No more ERR_MODULE_NOT_FOUND
errors during SessionStart hook.

Changes:
- Add src/cli-graceful.mjs - checks deps, runs npm install in background
- Build outputs cli-internal.mjs (bundled) + cli.mjs (wrapper copy)
- Update ensure-deps.sh to run silently in background
- Simplify hooks.json (no longer needs ensure-deps hook)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@baleen37
baleen37 enabled auto-merge February 10, 2026 05:14
@coderabbitai

coderabbitai Bot commented Feb 10, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR implements graceful dependency handling for the conversation-memory plugin by introducing a CLI wrapper that detects missing node_modules and launches a silent background npm install. The build system now outputs the core CLI as cli-internal.mjs while exposing a graceful wrapper as the entry point, and the hook timeout was reduced.

Changes

Cohort / File(s) Summary
Graceful CLI Wrapper
plugins/conversation-memory/src/cli-graceful.mjs
New wrapper script that checks for node_modules existence; spawns detached background npm install if missing; otherwise dynamically imports and delegates to cli-internal.mjs.
Build System Updates
plugins/conversation-memory/scripts/build.mjs
Modified build output to generate dist/cli-internal.mjs for the core CLI and added a build step to copy src/cli-graceful.mjs to dist/cli.mjs as the entry point.
Dependency Installation
plugins/conversation-memory/hooks/ensure-deps.sh
Replaced synchronous npm install with silent, detached background process that redirects output to /dev/null and exits immediately.
Hook Configuration
plugins/conversation-memory/hooks/hooks.json
Reduced SessionStart hook timeout from 10000ms to 1000ms.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A graceful wrapper hops so spry,

Checking node_modules on the sly,

When missing, spawns install unseen,

Then leaps to CLI, quiet and lean! 🚀

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/conversation-memory-first-run

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@baleen37
baleen37 merged commit 2b2d317 into main Feb 10, 2026
4 of 5 checks passed
@baleen37
baleen37 deleted the fix/conversation-memory-first-run branch February 10, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant