Skip to content

release: v2.7.0 - #66

Merged
Shinrai merged 9 commits into
masterfrom
release/2.7.0
Dec 21, 2025
Merged

Shinrai merged 9 commits into
masterfrom
release/2.7.0

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Dec 20, 2025 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

  • feat(hooks): implement missing documented features for hooks API (3d88ffe)
  • feat(hooks): always hooks receive full execution context with error information (a26ee59)
  • feat: implement 3-hook system (before/after/always) with cross-mode compatibility (9c75bea)
  • feat(hooks): add error source tracking and suppressErrors option (c7d8a8d)

🐛 Bug Fixes

No bug fixes

🔧 Other Changes

  • refactor(hooks): use WeakSet for error tracking instead of mutating error objects (1a801bf)
  • chore: bump version to 2.7.0 (de46bb2)
  • chore: bump version to 2.6.4 (1e21ba3)
  • docs: Add hook system documentation and enable/disable tests (9e8ba7e)

🏷️ Release Information

  • release: v2.7.0 - Implement 3-hook system (before/after/always) with cross-mode compatibility (6abb0d1)

👥 Contributors

@cldmv-bot cldmv-bot Bot added semver: explicit This release uses an explicitly specified version rather than an auto-detected bump release Marks a pull request as a pending release — merge to publish a new version labels Dec 20, 2025
@Shinrai
Shinrai requested a review from Copilot December 20, 2025 06:52
@Shinrai Shinrai self-assigned this Dec 20, 2025

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

Copilot AI 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.

Pull request overview

Copilot reviewed 21 out of 27 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Shinrai and others added 9 commits December 20, 2025 22:00
…cross-mode compatibility

- Add 'always' hook type that executes after every function call (read-only)
- Update HookManager.executeAlwaysHooks() for read-only final result observation
- Fix hooks to work seamlessly across all 4 combinations: eager/lazy  async/live
- Update both runtimes (async/live) with 3-hook flow: before  function  after  always
- Fix live runtime makeWrapper to properly set __slothletPath and call runWithCtx
- Fix lazy mode to expose __slothletPath immediately (not as promise) for hook matching
- Remove double hook execution in lazy mode by eliminating redundant runWithCtx calls
- Add comprehensive tests covering all 3 hook types and cross-mode scenarios (22/22 passing)
- Hooks now short-circuit correctly: before cancels  skip after  always still runs
- Add comprehensive hook system section to README with examples
- Document 3 hook types (before/after/always) with use cases
- Add short-circuit, pattern matching, and priority examples
- Add runtime control examples (enable/disable)
- Add 3 new tests for enable/disable functionality (25/25 passing)
- Document cross-mode compatibility and error handling
- Add hook management API documentation (list, off, clear)
- Add error source tracking to hooks system
  - Error hooks now receive detailed source information (type, hookId, hookTag, timestamp, stack)
  - Source types: 'before', 'function', 'after', 'always', 'unknown'
  - Enables precise error origin identification for debugging and monitoring

- Add suppressErrors option to hooks configuration
  - When true: errors sent to error hooks but NOT thrown (returns undefined)
  - When false (default): errors sent to error hooks THEN thrown (normal behavior)
  - Applies to all hook errors (before, after, function)
  - Always hook errors never throw regardless of setting

- Fix hooks API wrapper signatures
  - on() now returns hook ID for use with off()
  - on(name, type, handler, options) - correct parameter order
  - off(idOrPattern) - removed unsupported type parameter
  - clear() - removed unsupported type parameter

- Add errorType field to error context
  - Contains error.constructor.name for error class identification
  - Helps distinguish between different error types in monitoring

- Update both runtimes to respect suppressErrors
  - AsyncLocalStorage runtime: proper error suppression flow
  - Live bindings runtime: proper error suppression flow
  - Both check suppressErrors before re-throwing

- Add comprehensive documentation
  - Hook configuration section in README with suppressErrors examples
  - Error suppression behavior and use cases
  - Updated AGENT-USAGE.md with hooks system guide
  - Clear flow diagram of error handling

- Add comprehensive test coverage
  - test-hooks-error-source.mjs: 6 tests for error source tracking
  - test-hooks-suppress-errors.mjs: 15 tests for suppressErrors option
  - Tests cover all modes (eager/lazy  async/live)
  - All tests passing

- Add documentation files to package.json
  - API-RULES.md, API-RULES-CONDITIONS.md, AGENT-USAGE.md
  - Ensures critical documentation is distributed with npm package

BREAKING CHANGES: None (all changes are additive features)

Closes #hooks-improvements
…ompatibility

Add comprehensive hook system for intercepting and modifying API function calls with before, after, and always hook types. Includes error source tracking, suppressErrors option, and pattern-based filtering.

Features:
- 3-hook system: before (modify args/cancel), after (transform results), always (observe)
- Error hooks with detailed source tracking (type, hookId, hookTag, timestamp, stack)
- suppressErrors option to control error throwing behavior
- Pattern matching with wildcards (exact, namespace, function, all)
- Priority-based execution ordering
- Short-circuit support in before hooks
- Cross-mode compatibility (eager/lazy  async/live)

API:
- api.hooks.on(name, type, handler, options) - register hook with pattern and priority
- api.hooks.off(idOrPattern) - remove hook by ID
- api.hooks.enable(pattern) / disable() - runtime control
- api.hooks.clear() - remove all hooks
- api.hooks.list() - list registered hooks

Testing:
- 21 new tests covering all hook types and modes
- test-hooks-error-source.mjs: error source tracking
- test-hooks-suppress-errors.mjs: error suppression behavior
- All tests passing across all configurations
…nformation

Always hook handlers now receive complete execution context including error state, enabling unified logging of both success and error scenarios with a single hook.

Context object: { path, result, hasError, errors }
- hasError: boolean indicating if errors occurred during execution
- errors: array of Error objects (empty on success)
- result: final result (undefined on error)
- path: function path

Changes:
- Updated executeAlwaysHooks to accept errors array parameter
- Both AsyncLocalStorage and live bindings runtimes pass error context
- Success paths pass empty errors array, error paths pass array with error
- Updated README with new always hook context documentation and examples
- Added comprehensive test suite (7 tests) for always hook error context
- Added math.divide function to test API for error testing scenarios

Benefits:
- Single always hook handles both success and error logging
- Perfect for metrics, monitoring, and unified execution tracking
- Maintains always hook guarantee: runs even when errors are suppressed
- Eliminates need for separate error + always hooks for complete logging
…rror objects

Replaced error._hookSourceReported property mutation with WeakSet-based tracking to avoid issues with frozen or non-extensible error objects.

Changes:
- Added reportedErrors WeakSet to HookManager constructor
- Updated before/after hooks error handling to use reportedErrors.add()
- Updated both runtimes to check reportedErrors.has() before executing error hooks
- Prevents duplicate error hook executions without mutating error objects

Benefits:
- Works reliably with all error types including frozen objects
- No mutation of error objects from external libraries
- Cleaner approach that respects error object immutability
- WeakSet allows garbage collection of error references
Implemented pattern-based removal, type filtering, and documented handler signatures to match README documentation.

Changes:
- Implemented pattern-based removal in off() method using glob pattern matching
- Implemented type filtering in clear() method to remove hooks by type
- Implemented type filtering in list() method to filter hooks by type
- Updated on() JSDoc to document handler signatures for each hook type:
  * before: ({ path, args }) => modified args or short-circuit value
  * after: ({ path, result }) => transformed result
  * always: ({ path, result, hasError, errors }) => void
  * error: ({ path, error, errorType, source }) => void
- Updated hooks API wrapper in slothlet.mjs to pass type parameter to clear()
- Added comprehensive test suite (11 tests) verifying:
  * Internal properties don't trigger hooks
  * Pattern-based removal works correctly
  * Type filtering for clear() and list() works correctly

Benefits:
- Full feature parity with documented API
- Pattern-based hook removal: api.hooks.off('math.*')
- Type-specific clearing: api.hooks.clear('before')
- Type-specific listing: api.hooks.list('before')
- Clear documentation of handler signatures per hook type
@Shinrai
Shinrai merged commit 25657d3 into master Dec 21, 2025
Shinrai added a commit that referenced this pull request Feb 11, 2026
# Release: v2.7.0 - Complete Hooks System Implementation

🚀 **MAJOR FEATURE RELEASE - COMPREHENSIVE HOOKS SYSTEM FOR API INTERCEPTION**
• Implement complete 4-hook system (before/after/always/error) enabling sophisticated function interception patterns across both lazy and eager loading modes
• Add error source tracking providing detailed context about error origins (before hook, function, after hook, always hook) with hook ID, tag, timestamp, and stack traces
• Introduce suppressErrors option allowing error observation without execution failure, enabling non-blocking error monitoring and logging patterns
• Enhance always hooks with full execution context including error state (hasError, errors array) enabling unified success/error logging with single hook
• Implement pattern-based hook removal, type filtering for list/clear operations achieving full feature parity with documented API

✨ **HOOK SYSTEM ARCHITECTURE AND CAPABILITIES**
• Before hooks: Modify function arguments, short-circuit execution with custom return values, implement validation/caching patterns with priority-based execution
• After hooks: Transform function results, chain multiple transformations in priority order, only execute when functions complete (skipped on short-circuit)
• Always hooks: Observe final results with complete context (path, result, hasError, errors), run like finally blocks even when errors occur or execution cancelled
• Error hooks: Monitor errors with detailed source tracking, receive error type/class information, perfect for centralized error monitoring and alerting systems
• Pattern matching: Glob-based path filtering (*, **, {alt1,alt2}, !negation) with priority-based execution order ensuring predictable hook behavior

🔒 **ERROR HANDLING AND RELIABILITY IMPROVEMENTS**
• Error source tracking: Detailed origin information (type: 'before'|'function'|'after'|'always', hookId, hookTag, timestamp, stack) enabling precise error debugging
• suppressErrors option: Error hooks always execute, errors thrown only when suppressErrors=false (default), enabling graceful degradation patterns
• WeakSet-based error tracking: Replaced error object mutation with WeakSet preventing issues with frozen/non-extensible errors from external libraries
• Always hooks error context: Full execution context with hasError boolean and errors array eliminating need for separate error+always hooks for comprehensive logging
• Cross-mode compatibility: Identical hook behavior across AsyncLocalStorage and live-bindings runtimes ensuring consistent interception patterns

🛠️ **API ENHANCEMENTS AND FEATURE PARITY**
• Pattern-based removal: api.hooks.off('math.*') removes all matching hooks using glob pattern compilation with negation support
• Type filtering for clear: api.hooks.clear('before') removes only specified hook type, api.hooks.clear() removes all hooks
• Type filtering for list: api.hooks.list('before') returns filtered hooks, api.hooks.list() returns all hooks with metadata
• Handler signature documentation: Clear parameter documentation for each hook type preventing confusion during registration
• Internal property protection: hooks, __ctx, shutdown, _impl properties excluded from hook execution preventing infinite recursion

**Technical Implementation**:
- Complete HookManager class with priority-based execution, glob pattern matching, WeakSet error tracking, and type filtering
- Integrated hook execution into both runtime systems (AsyncLocalStorage and live-bindings) maintaining performance characteristics
- executeAlwaysHooks enhanced to accept errors array parameter, passing empty array on success, error array on failure
- Pattern compilation supporting *, **, brace expansion {a,b}, negation !pattern with maximum nesting depth protection
- Hooks API wrapper exposing on/off/enable/disable/clear/list methods with full parameter forwarding

**Use Case Examples**: 
- Unified logging: Single always hook handles both success and error scenarios with conditional logic based on hasError flag
- Metrics tracking: Monitor call counts, success rates, error rates across API functions using pattern-matched hooks
- Caching: Before hooks check cache, short-circuit on hit, after hooks populate cache on miss
- Authorization: Before hooks validate permissions, cancel execution for unauthorized access
- Error monitoring: Error hooks report to monitoring service with full source context for debugging

**Impact Assessment**: 
Enhanced capabilities - sophisticated function interception patterns enable advanced monitoring, caching, validation, and transformation scenarios; improved developer experience through unified logging patterns and clear handler signatures; enhanced reliability through WeakSet-based error tracking and consistent cross-mode behavior; maintained performance characteristics with minimal overhead for disabled hooks fast-path.

**Testing Coverage**: 
Comprehensive test suite with 40+ tests covering hook execution order, priority handling, pattern matching, error source tracking, suppressErrors behavior, always hook error context, pattern-based removal, type filtering, internal property protection, and cross-mode consistency.

Breaking Changes: None - completely additive feature set with no API modifications
Performance Impact: Minimal - hooks disabled by default, fast-path bypass when disabled, lazy materialization preserved
Hook Reliability: Production-ready - comprehensive testing, WeakSet immutability, consistent behavior across modes

This release establishes slothlet as a sophisticated module loader with enterprise-grade function interception capabilities, enabling advanced monitoring, caching, validation, and transformation patterns while maintaining the performance characteristics that define the framework.

Co-authored-by: Nate - CLDMV <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release Marks a pull request as a pending release — merge to publish a new version semver: explicit This release uses an explicitly specified version rather than an auto-detected bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants