Skip to content

Conversation

mkczarkowski
Copy link
Collaborator

Problem

The Single and Multi-file rules generation strategies contained significant code duplication:

  • Both strategies duplicated project header setup logic
  • Empty-state messaging was repeated in both files
  • Library iteration and markdown generation logic was implemented separately
  • This duplication made it harder to maintain consistency and add new features

Solution

Extracted common scaffolding into a shared markdown-builders module that provides reusable utilities:

New Shared Builders

  • createProjectMarkdown - Generates consistent project headers
  • createEmptyStateMarkdown - Returns standardized empty state message
  • getProjectMetadata - Provides standard project file metadata
  • renderLibrarySection - Renders library markdown with configurable headers
  • iterateLayersStacksLibraries - Unified iteration logic over layer/stack/library structure
  • createLibraryFileMetadata - Generates file metadata for multi-file output

Key Benefits

Single source of truth - All markdown generation logic now lives in one place
Guaranteed consistency - Both strategies use the same builders, ensuring uniform formatting
Easier maintenance - Changes to formatting only need to be made once
Reduced complexity - Strategies are now simpler and focus on their core responsibility
Better testability - Shared builders can be tested independently
Future-proof - Adding new strategies is now much simpler

Changes Made

  1. Created new src/services/rules-builder/markdown-builders/index.ts module
  2. Refactored SingleFileRulesStrategy to use shared builders
  3. Refactored MultiFileRulesStrategy to use shared builders
  4. Removed duplicated code from both strategies

Testing

  • ✅ All existing unit tests pass
  • ✅ Linting passes with no errors
  • ✅ No functional changes - output remains identical

🤖 Generated with Claude Code

…egies

Extract common scaffolding from Single and Multi file strategies into reusable builders module. This reduces code duplication and ensures consistent formatting across both strategies.

Key changes:
- Created markdown-builders module with shared utilities
- Extracted project header, empty state, and library section rendering
- Unified iteration logic over layer/stack/library structure
- Simplified both strategies to use shared builders

Benefits:
- Guarantees consistent formatting across strategies
- Reduces effort when adding new strategies
- Single source of truth for markdown generation logic
- Easier maintenance and testing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

✅ All checks have passed successfully!

  • Lint: ✅
  • Unit Tests: ✅
  • E2E Tests: ✅

Coverage reports have been uploaded as artifacts.

@przeprogramowani przeprogramowani merged commit 6e06740 into master Sep 26, 2025
5 checks passed
@przeprogramowani przeprogramowani deleted the refactor-markdown-builders branch September 26, 2025 18:22
@mkczarkowski mkczarkowski restored the refactor-markdown-builders branch September 29, 2025 12:36
mkczarkowski added a commit that referenced this pull request Oct 4, 2025
* refactor: extract shared markdown builders for rules generation strategies (#73)

Extract common scaffolding from Single and Multi file strategies into reusable builders module. This reduces code duplication and ensures consistent formatting across both strategies.

Key changes:
- Created markdown-builders module with shared utilities
- Extracted project header, empty state, and library section rendering
- Unified iteration logic over layer/stack/library structure
- Simplified both strategies to use shared builders

Benefits:
- Guarantees consistent formatting across strategies
- Reduces effort when adding new strategies
- Single source of truth for markdown generation logic
- Easier maintenance and testing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>

* refactor: centralize keyboard activation handling (#71)

* refactor: centralize keyboard activation handling

* test: add coverage for useKeyboardActivation hook

* docs: add prompt-manager plans and custom prompts

* docs: updates to reflect feedback

* docs: create prd

* feat: implement phase 1 (flags and access)

* feat: implement phase 2 (organizations)

* fix: remove typo from impl plan documents

* feat: implement phase 3 (prompt collections and admin apis)

* refactor: rename collections to differentiate between prompts and collections

* feat: implement phase 4 (member api and ui)

* feat: implement phase 5 (admin ui)

* feat: implement phase 7 (localization)

* feat: add UI adjustments

* fix: handle localization in search

* feat: implement link to prompt

* feat: implement invite links

* feat: apply RLS to protect access

* refactor: simplify test mocks

* refactor: rename prompt manager to prompt library

* chore: update migrations order and consolidate rls

* chore: cleanup docs

* feat: enable prompt library on prod

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants