Skip to content

Conversation

@cldmv-bot
Copy link
Contributor

@cldmv-bot cldmv-bot bot commented Jan 4, 2026

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

  • feat: Add Rule 11 (AddApi Special File Pattern) and extend Rule 1 to addApi context (efd2020)
  • feat: enhance addApi content preservation and smart flattening validation (c368d05)

🐛 Bug Fixes

  • Potential fix for code scanning alert no. 34: Workflow does not contain permissions (516babc)
  • fix: update minimum Node.js version to 16.20.2 due to stack trace regression (868b6e1)
  • fix(resolve-from-caller): Filter ALL node: built-in modules, not just node:internal (2ff1b25)
  • fix(resolve-from-caller): Skip all internal files after slothlet.mjs to find actual caller (505ace6)
  • fix: correct Rule 12 test validation logic (b34e3c9)
  • fix: complete test-smart-flattening-api.mjs - all 168 tests passing (e338e62)
  • fix: addApi multiple calls preserve content in lazy mode (84d818a)
  • fix: addApi merge logic for multiple calls (500efb8)

🔧 Other Changes

  • Merge branch 'release/v2.11.0' of https://github.com/CLDMV/slothlet into release/v2.11.0 (5ac281f)
  • chore: clean up unused imports and exclude test files from type generation (64a37d9)
  • chore: bump version to 2.11.0 (fe67467)
  • docs: Add Rule 11 (AddApi Special File Pattern) documentation across all MD files (405a78c)
  • docs: Update v2.11.md changelog with Rule 11 and Rule 1 extension features (f173ca7)
  • docs: Comprehensive update to API documentation suite (e71e8d1)

👥 Contributors

Shinrai and others added 12 commits January 2, 2026 18:50
- Fixed Object.assign merging in decisions.mjs to merge objects instead of overwriting
- addApi now properly merges content when called multiple times on same API path
- Multiple addApi calls to same path (e.g. 'config') now accumulate functions correctly
- Test shows second addApi call properly merges with first call results

Internal single-folder conflicts still need fixing:
- Root-level config.mjs + config/config.mjs conflict within single addApi call
- Subdirectory flattening still overwrites root-level file during initial load
- Rule 7 implementation needs adjustment to handle this case
- Fixed issue where multiple addApi calls were overwriting previous content instead of merging
- Root cause: lazy mode module loading was corrupting bound API state before content preservation
- Solution: capture existing API content before module loading (super early capture)
- Added object reference isolation to prevent contamination during merge operations
- Lazy mode now matches eager mode behavior for root-level file + subdirectory conflicts
- Both test-addapi-conflict.mjs and test-lazy-mode-conflict.mjs now pass
- All 8 expected functions preserved across multiple addApi calls
- Fixed test expectations to match Rule 1 flattening behavior (filename matches folder name)
- Corrected config/config.mjs scenarios to expect flattening at root level
- Updated services/services/services.mjs tests for proper Rule 1 flattening
- Fixed autoFlatten=false tests to understand Rule 1 applies regardless of setting
- Added lazy mode materialization support with isValidFolderType() helper
- Fixed lazy mode typeof assertions to accept functions as valid folder types
- Added proper materialization triggers by accessing nested properties before checks
- All eager/lazy modes across async/live runtimes and hook configurations now pass
- Enhanced API-FLATTENING.md with 3-tier navigation system (F01-F07)
- Updated API-RULES.md with verified examples and cross-references (Rules 1-12)
- Corrected API-RULES-CONDITIONS.md with accurate source code verification (C01-C18)
- Added complete cross-reference system linking all documentation levels
- Verified all technical details against current source code implementation
- Improved user experience with clear navigation and enhanced examples
- All content preserved while significantly improving accuracy and usability
…tion

- Fixed addApi multiple calls content preservation with early capture mechanism
- Added comprehensive 168-scenario test coverage for smart flattening behaviors
- Enhanced precommit validation pipeline with automatic build artifact cleanup
- Improved TypeScript definition generation with JSDoc typedef patterns
- Resolved 140+ lint errors for improved code quality standards

Technical improvements:
- Object reference isolation prevents content contamination during merge operations
- Super early content capture before module loading in lazy mode
- Enhanced merge logic in decisions.mjs for proper content accumulation
- Comprehensive validation across async/live runtimes and hook configurations

API behavior discoveries:
- Single file mixed exports: api.mixed() callable with api.mixed.methods()
- Root-level mixed exports: api.volume() callable with api.volume.up() methods
- Identified callable namespace gap for subfolder multiple-file scenarios

Documentation updates:
- Enhanced API documentation suite with 3-tier navigation system
- Updated changelog and README for v2.11.0 release preparation
- Verified examples and cross-references across all documentation levels

This enhances module loading reliability and provides comprehensive validation
for complex API structures while maintaining backward compatibility.
…addApi context

This commit adds two new API generation features that extend slothlet's
flattening capabilities to the addApi() runtime extension system:

Feature 1: Rule 11 - AddApi Special File Pattern
- Files named addapi.mjs loaded via addApi() method always flatten
- Behavior independent of autoFlatten setting
- Designed for seamless API namespace extensions
- Implementation in src/lib/helpers/api_builder/add_api.mjs

Feature 2: Rule 1 Extended to AddApi Context
- Filename-matches-container flattening now works with addApi()
- When folder name matches filename in addApi context, content flattens to category level
- Example: plugins/plugins.mjs via addApi("plugins", "./plugins") results in api.plugins.method()
- Prevents redundant nesting (api.plugins.plugins.method) in dynamic API extensions

Implementation Details:
- Added special case handling for addapi.mjs files in addApiFromFolder()
- Extended getFlatteningDecision() to recognize container-matching in addApi context
- Unified construction architecture ensures consistent behavior across eager/lazy modes
- Added callable namespace pattern constraint (single module only) to prevent circular references

Test Coverage:
- api_tests/api_smart_flatten_addapi/: Rule 11 verification
- tests/debug-slothlet.mjs: API structure validation
- All precommit tests pass (7/7 steps)

Related Documentation:
- docs/API-RULES.md: Rule 11 and Rule 1 extended documentation
- docs/API-FLATTENING-v2.md: F06 pattern documentation
- docs/changelog/v2.11.md: Feature changelog entry

These features enable cleaner API extensions via addApi() while maintaining
predictable structure and preventing common pitfalls like circular references
and redundant nesting in dynamically loaded modules.
…all MD files

- API-RULES-CONDITIONS.md: Added comprehensive C33 condition section
  * Implementation details from add_api.mjs lines 266-310
  * Code examples showing always-flatten behavior
  * Use cases for plugin systems and runtime extensions

- README.md: Updated v2.11.0 highlights
  * Added Rule 11 feature to what's new section
  * Added Rule 1 extension (filename-matches-container in addApi)

- AGENT-USAGE.md: Added Pattern 5 for AddApi Special File Pattern
  * Complete code example for addapi.mjs usage
  * Use cases: plugin systems, hot reloading, modular extensions
  * Cross-references to API-RULES.md Rule 11

Related commits: efd2020, f173ca7
- Add missing pathToFileURL import for ESM module detection
- Fix config validation test to properly test enableModuleOwnership requirement
  * Added moduleId parameter so test reaches enableModuleOwnership check
  * Previously was failing on missing moduleId check first
- Fix allowApiOverwrite interaction test expectations
  * Changed from expecting error throw to verifying API reference unchanged
  * Aligns with non-breaking design: warns and skips instead of throwing
- All 17 test configurations now pass (100% success rate)
- Precommit validation passes all steps
…to find actual caller

Previous algorithm would give up at the first internal file after slothlet.mjs,
causing path resolution to fall back incorrectly in CI where runtime files appear
between slothlet.mjs and user code in the stack trace.

Now loops through all frames after slothlet.mjs, skipping:
- All internal files (src/lib/*, helpers/*)
- All index files (index.mjs, index.cjs, index.js)

Until it finds the actual user code that called addApi.

This fixes CI path resolution errors where ../api_tests/* was resolving from
the wrong directory level (one level too high).

Changes:
- resolve-from-caller.mjs: Replace single-check logic with while loop
- Added comprehensive path resolution tests
- Fixed test runner to exclude helper utilities properly
… node:internal

Previous fix only filtered node:internal/* but CI was finding node:async_hooks
and other built-in modules (node:fs, node:path, etc.) in the stack trace.

When resolving paths from node:async_hooks, ../api_tests/* would resolve to
the wrong directory level.

Now filters ALL node:* modules in three places:
- pickPrimaryBaseFile initial stack filtering
- Candidate checking loop after slothlet.mjs
- pickFallbackBaseFile stack filtering

This ensures we only resolve paths from actual user code files, never from
Node.js built-in modules.
…ression

- Update minimum Node.js version from 16.4.0 to 16.20.2
- Reason: Node.js 16.4-16.19 has stack trace API regression affecting path resolution
- Regression causes stack traces to omit user code frames in async contexts with AsyncLocalStorage
- Node.js 16.20.2+ fixes this issue and provides consistent behavior

Changes:
- package.json: engines.node >=16.20.2
- CI workflows: min_node_version 16.20.2, max_node_major 24
- README.md: Updated requirements and runtime documentation
- docs/CONTEXT-PROPAGATION.md: Updated performance note
- docs/changelog/v2.11.md: Added breaking changes section

Impact:
- Users on Node.js 16.4-16.19 must upgrade to 16.20.2+ or use slothlet@2.10.0
- CI will now test against Node.js 16.20.2, 17.x, 18.x, 20.x, 22.x, 24.x
- Local testing confirmed 16.20.2 works correctly (100% test pass rate)

Closes path resolution failures in Node.js 16.4.2 CI environment
…in permissions

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

This comment was marked as resolved.

…ation

- Remove unused 'reference' imports from api_adb_test files
  - inputHelpers.mjs, device.mjs, helpers.mjs, power.mjs, metadata.mjs, state.mjs
  - Files only import what they actually use (self and context)

- Exclude api_tests directory from TypeScript type generation
  - Added '../api_tests' to tsconfig.dts.jsonc exclude list
  - Test files don't need type definitions
  - Removes type-check warnings for test-only code

- Remove unnecessary || {} fallbacks in debug logging
  - Variables guaranteed to be objects don't need fallback
  - Fixes Copilot warnings about always-true conditions
  - Affected: superEarlyExistingTargetContent, superEarlyExistingBoundContent, newModules

Changes improve code clarity and reduce noise from linter/Copilot warnings
@Shinrai Shinrai requested a review from Copilot January 5, 2026 00:20

This comment was marked as resolved.

@Shinrai Shinrai merged commit 8ecbc32 into master Jan 5, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants