Skip to content

refactor(suggest-compacting): simplify TypeScript structure by removing Jest - #334

Merged
baleen37 merged 2 commits into
mainfrom
refactor/suggest-compacting-simplify
Feb 2, 2026
Merged

refactor(suggest-compacting): simplify TypeScript structure by removing Jest#334
baleen37 merged 2 commits into
mainfrom
refactor/suggest-compacting-simplify

Conversation

@baleen37

@baleen37 baleen37 commented Feb 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Remove Jest testing infrastructure to simplify the plugin
  • Flatten directory structure from src/hooks/* to src/*
  • Inline type definitions directly in each file (removed src/types/)
  • Update all file references in hooks.json and BATS tests
  • Reduce dependencies to minimum: typescript, tsx, @types/node

Changes

Removed

  • Jest configuration and test infrastructure (jest.config.cjs, unit tests, helpers)
  • src/types/index.ts - types now inlined where used
  • src/hooks/ directory nesting
  • .claude-plugin/hooks.json duplicate file
  • 4,233 lines total (mostly from package-lock.json)

Restructured

  • src/hooks/auto-compact.tssrc/auto-compact.ts
  • src/hooks/session-start.tssrc/session-start.ts
  • src/hooks/lib/state.tssrc/lib/state.ts

Updated

  • hooks/hooks.json - updated paths to new file locations
  • tsconfig.json - removed tests exclude
  • tests/suggest-compacting/suggest-compacting.bats - updated all test paths and expectations

Benefits

  • Simpler structure: Flatter directory hierarchy, easier to navigate
  • Smaller footprint: 4,000+ lines removed from dependencies
  • Maintained functionality: All features work identically
  • Type safety preserved: TypeScript + tsx for direct execution without build step
  • All tests pass: 16 BATS tests pass, pre-commit hooks pass

Test Plan

  • TypeScript type check passes (npx tsc --noEmit)
  • Manual execution tests (session-start, auto-compact)
  • Functional tests (50th, 75th suggestion messages)
  • Security validation (path traversal attack prevention)
  • All 16 BATS tests pass
  • Pre-commit hooks pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Reorganized plugin directory structure for improved maintainability.
    • Removed testing framework and related development dependencies.
  • Refactor

    • Simplified plugin configuration and hook structure.
    • Updated build configuration to streamline compilation process.

…ng Jest

- Remove Jest testing infrastructure (jest.config.cjs, unit tests, helpers)
- Simplify file structure: src/hooks/* → src/*, src/types/* (deleted)
- Inline type definitions directly in each file
- Update hooks.json paths to reference new file locations
- Update BATS tests to reflect new structure
- Keep TypeScript + tsx for type safety without build step
- Reduce dependencies to minimum: typescript, tsx, @types/node

Benefits:
- 4000+ lines removed from package-lock.json
- Simpler, flatter directory structure
- Maintains all functionality and type safety
- No build process needed (tsx direct execution)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@baleen37
baleen37 enabled auto-merge (squash) February 2, 2026 08:45
@coderabbitai

coderabbitai Bot commented Feb 2, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR reorganizes the suggest-compacting plugin structure by moving hook configurations from .claude-plugin/ to hooks/, removing Jest testing infrastructure, internalizing type definitions, and updating corresponding test files to reflect the new layout.

Changes

Cohort / File(s) Summary
Plugin Hook Configuration
plugins/suggest-compacting/.claude-plugin/hooks.json, plugins/suggest-compacting/hooks/hooks.json
Relocated hooks.json to new directory structure and updated hook command paths from src/hooks/ to src/.
Build & Testing Configuration
plugins/suggest-compacting/jest.config.cjs, plugins/suggest-compacting/package.json, plugins/suggest-compacting/tsconfig.json
Removed Jest configuration and dev dependencies; narrowed TypeScript compilation exclusions from ["node_modules", "dist", "tests"] to ["node_modules"].
Type Definitions
plugins/suggest-compacting/src/types/index.ts
Deleted exported interfaces (SessionStartInput, PreToolUseInput, ToolCountState) from the public API surface.
Source Code
plugins/suggest-compacting/src/lib/state.ts
Replaced external ToolCountState import with a locally-defined interface definition.
Testing Infrastructure & Helpers
plugins/suggest-compacting/tests/helpers/bats_helper.bash, plugins/suggest-compacting/tests/unit/state.test.ts
Removed Bash test helper utility and Jest unit test file for state management.
Integration Tests
tests/suggest-compacting/suggest-compacting.bats
Updated test paths and assertions to reference new plugin structure (hooks/hooks.json, src/ instead of src/hooks/) and verify absence of Jest dependencies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Files shuffled, paths refined,
Jest removed, new structure aligned,
Types tucked in where they belong,
Tests rewritten, ever strong,
A plugin reorganized with care! 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: refactoring to simplify the TypeScript structure by removing Jest testing infrastructure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 refactor/suggest-compacting-simplify

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@plugins/suggest-compacting/src/lib/state.ts`:
- Line 9: The STATE_DIR definition uses process.env.HOME with an empty-string
fallback which can produce a relative path; update the code that builds
STATE_DIR (symbol: STATE_DIR) to use a reliable home directory API (e.g.,
require('os').homedir()) or explicitly throw if no home directory is available
so the path is always absolute; adjust the import/require to include os if
needed and ensure the new logic guarantees an absolute path or raises a clear
error instead of falling back to ''.

sessionId: string;
}

const STATE_DIR = path.join(process.env.HOME || '', '.claude', 'suggest-compacting');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Empty string fallback for HOME may cause unexpected behavior.

If process.env.HOME is undefined, the path becomes .claude/suggest-compacting (a relative path), which could write state files to the current working directory instead of the user's home directory. Consider throwing an error or using a more robust fallback.

🛡️ Proposed fix
-const STATE_DIR = path.join(process.env.HOME || '', '.claude', 'suggest-compacting');
+const STATE_DIR = path.join(
+  process.env.HOME || process.env.USERPROFILE || (() => { throw new Error('HOME environment variable is not set'); })(),
+  '.claude',
+  'suggest-compacting'
+);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const STATE_DIR = path.join(process.env.HOME || '', '.claude', 'suggest-compacting');
const STATE_DIR = path.join(
process.env.HOME || process.env.USERPROFILE || (() => { throw new Error('HOME environment variable is not set'); })(),
'.claude',
'suggest-compacting'
);
🤖 Prompt for AI Agents
In `@plugins/suggest-compacting/src/lib/state.ts` at line 9, The STATE_DIR
definition uses process.env.HOME with an empty-string fallback which can produce
a relative path; update the code that builds STATE_DIR (symbol: STATE_DIR) to
use a reliable home directory API (e.g., require('os').homedir()) or explicitly
throw if no home directory is available so the path is always absolute; adjust
the import/require to include os if needed and ensure the new logic guarantees
an absolute path or raises a clear error instead of falling back to ''.

@baleen37
baleen37 merged commit 7343fa2 into main Feb 2, 2026
2 checks passed
@baleen37
baleen37 deleted the refactor/suggest-compacting-simplify branch February 2, 2026 08:53
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