From 56213ef84aa3e78624e6d35a7d9a3c61304f814d Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Sun, 26 Oct 2025 00:44:04 -0400 Subject: [PATCH] Fix: Update npm loglevel to silent in SessionStart hook to prevent context injection issues; consolidate hooks architecture and update documentation for v4.3.1 --- .gitignore | 3 ++- docs/architecture/hooks.mdx | 19 +++++++-------- docs/architecture/overview.mdx | 9 +------- docs/development.mdx | 42 +++++++++++++++------------------- docs/introduction.mdx | 21 ++++++++++------- 5 files changed, 45 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index ae631343..638bdcbb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ node_modules/ .claude/settings.local.json plugin/data/ plugin/data.backup/ -package-lock.json \ No newline at end of file +package-lock.json +private/ \ No newline at end of file diff --git a/docs/architecture/hooks.mdx b/docs/architecture/hooks.mdx index d103382f..bd05264a 100644 --- a/docs/architecture/hooks.mdx +++ b/docs/architecture/hooks.mdx @@ -28,7 +28,7 @@ Hooks are configured in `plugin/hooks/hooks.json`: "SessionStart": [{ "hooks": [{ "type": "command", - "command": "cd \"${CLAUDE_PLUGIN_ROOT}/..\" && npm install --prefer-offline --no-audit --no-fund --loglevel=error && node ${CLAUDE_PLUGIN_ROOT}/scripts/context-hook.js", + "command": "cd \"${CLAUDE_PLUGIN_ROOT}/..\" && npm install --prefer-offline --no-audit --no-fund --loglevel=silent && node ${CLAUDE_PLUGIN_ROOT}/scripts/context-hook.js", "timeout": 120 }] }], @@ -91,7 +91,9 @@ Hooks are configured in `plugin/hooks/hooks.json`: } ``` -**Implementation**: `src/hooks/context.ts` and `src/bin/hooks/context-hook.ts` +**Implementation**: `src/hooks/context-hook.ts` + +**v4.3.1 Fix**: Changed npm install to use `--loglevel=silent` instead of `--loglevel=error` to prevent output pollution that was breaking JSON context injection. ## 2. UserPromptSubmit Hook (`new-hook.js`) @@ -112,7 +114,7 @@ Hooks are configured in `plugin/hooks/hooks.json`: } ``` -**Implementation**: `src/hooks/new.ts` and `src/bin/hooks/new-hook.ts` +**Implementation**: `src/hooks/new-hook.ts` ## 3. PostToolUse Hook (`save-hook.js`) @@ -136,7 +138,7 @@ Hooks are configured in `plugin/hooks/hooks.json`: } ``` -**Implementation**: `src/hooks/save.ts` and `src/bin/hooks/save-hook.ts` +**Implementation**: `src/hooks/save-hook.ts` ## 4. Stop Hook (`summary-hook.js`) @@ -156,7 +158,7 @@ Hooks are configured in `plugin/hooks/hooks.json`: } ``` -**Implementation**: `src/hooks/summary.ts` and `src/bin/hooks/summary-hook.ts` +**Implementation**: `src/hooks/summary-hook.ts` ## 5. SessionEnd Hook (`cleanup-hook.js`) @@ -177,16 +179,15 @@ Hooks are configured in `plugin/hooks/hooks.json`: } ``` -**Implementation**: `src/hooks/cleanup.ts` and `src/bin/hooks/cleanup-hook.ts` +**Implementation**: `src/hooks/cleanup-hook.ts` ## Hook Development ### Adding a New Hook 1. Create hook implementation in `src/hooks/your-hook.ts` -2. Create entry point in `src/bin/hooks/your-hook.ts` -3. Add to `plugin/hooks/hooks.json` -4. Rebuild with `npm run build` +2. Add to `plugin/hooks/hooks.json` +3. Rebuild with `npm run build` ### Hook Best Practices diff --git a/docs/architecture/overview.mdx b/docs/architecture/overview.mdx index fc633cec..a16c2c11 100644 --- a/docs/architecture/overview.mdx +++ b/docs/architecture/overview.mdx @@ -90,20 +90,13 @@ Claude Request → MCP Server → SessionSearch Service → FTS5 Database → Se ``` claude-mem/ ├── src/ -│ ├── bin/hooks/ # Entry point scripts for 5 hooks +│ ├── hooks/ # Hook implementations (v4.3.1+ consolidated) │ │ ├── context-hook.ts # SessionStart │ │ ├── new-hook.ts # UserPromptSubmit │ │ ├── save-hook.ts # PostToolUse │ │ ├── summary-hook.ts # Stop │ │ └── cleanup-hook.ts # SessionEnd │ │ -│ ├── hooks/ # Hook implementation logic -│ │ ├── context.ts -│ │ ├── new.ts -│ │ ├── save.ts -│ │ ├── summary.ts -│ │ └── cleanup.ts -│ │ │ ├── servers/ # MCP servers │ │ └── search-server.ts # MCP search tools server │ │ diff --git a/docs/development.mdx b/docs/development.mdx index e3be0df3..d82f7c2a 100644 --- a/docs/development.mdx +++ b/docs/development.mdx @@ -61,8 +61,7 @@ Edit TypeScript source files in `src/`: ``` src/ -├── bin/hooks/ # Hook entry points -├── hooks/ # Hook implementations +├── hooks/ # Hook implementations (entry points + logic) ├── services/ # Worker service and database ├── servers/ # MCP search server ├── sdk/ # Claude Agent SDK integration @@ -118,34 +117,27 @@ Repeat steps 1-4 until your changes work as expected. 1. Create hook implementation in `src/hooks/your-hook.ts`: -```typescript -import { HookInput } from './types'; - -export async function yourHook(input: HookInput) { - // Hook implementation - return { - hookSpecificOutput: 'Optional output' - }; -} -``` - -2. Create entry point in `src/bin/hooks/your-hook.ts`: - ```typescript #!/usr/bin/env node -import { readStdin } from '../../shared/stdin'; -import { yourHook } from '../../hooks/your-hook'; +import { readStdin } from '../shared/stdin'; async function main() { const input = await readStdin(); - const result = await yourHook(input); + + // Hook implementation + const result = { + hookSpecificOutput: 'Optional output' + }; + console.log(JSON.stringify(result)); } main().catch(console.error); ``` -3. Add to `plugin/hooks/hooks.json`: +**Note**: As of v4.3.1, hooks are self-contained files. The shebang will be added automatically by esbuild during the build process. + +2. Add to `plugin/hooks/hooks.json`: ```json { @@ -424,18 +416,22 @@ The `release` script: 6. Publish to NPM ```bash -# Update version -npm version 4.2.4 +# Use the version bump skill (recommended as of v4.3.0) +# In Claude Code, run: /skill version-bump +# This updates package.json, marketplace.json, and CLAUDE.md + +# Or manually: +npm version 4.3.2 # Update changelog # Edit CHANGELOG.md manually # Commit git add . -git commit -m "chore: Release v4.2.4" +git commit -m "chore: Release v4.3.2" # Tag -git tag v4.2.4 +git tag v4.3.2 # Push git push origin main --tags diff --git a/docs/introduction.mdx b/docs/introduction.mdx index 47d7b772..51038e95 100644 --- a/docs/introduction.mdx +++ b/docs/introduction.mdx @@ -67,16 +67,21 @@ See [Architecture Overview](architecture/overview) for details. - **PM2**: Process manager (bundled - no global install required) - **SQLite 3**: For persistent storage (bundled) -## What's New in v4.2.3 +## What's New in v4.3.1 -**Security:** -- Fixed FTS5 injection vulnerability in search functions -- Added comprehensive test suite with 332 injection attack tests +**Critical Fix:** +- Fixed SessionStart hook context injection (v4.3.1) + - Context wasn't being injected due to npm output pollution + - Changed npm loglevel to `--loglevel=silent` for clean JSON output -**Fixes:** -- Fixed ESM/CJS compatibility for getDirname function -- Fixed Windows PowerShell compatibility in SessionStart hook -- Cross-platform dependency installation now works on Windows, macOS, and Linux +**Code Quality:** +- Consolidated hooks architecture (removed bin/hooks wrapper layer) +- Fixed double shebang issues in hook executables + +**Recent Updates (v4.3.0):** +- Progressive disclosure context with observation timelines +- Enhanced session summaries with token cost visibility +- Cross-platform path detection improvements ## Next Steps