refactor(suggest-compacting): simplify TypeScript structure by removing Jest - #334
Conversation
…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>
📝 WalkthroughWalkthroughThe PR reorganizes the suggest-compacting plugin structure by moving hook configurations from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
| 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 ''.
Summary
src/hooks/*tosrc/*src/types/)Changes
Removed
src/types/index.ts- types now inlined where usedsrc/hooks/directory nesting.claude-plugin/hooks.jsonduplicate fileRestructured
src/hooks/auto-compact.ts→src/auto-compact.tssrc/hooks/session-start.ts→src/session-start.tssrc/hooks/lib/state.ts→src/lib/state.tsUpdated
hooks/hooks.json- updated paths to new file locationstsconfig.json- removed tests excludetests/suggest-compacting/suggest-compacting.bats- updated all test paths and expectationsBenefits
Test Plan
npx tsc --noEmit)🤖 Generated with Claude Code
Summary by CodeRabbit
Chores
Refactor