Skip to content

refactor(adf): split bundler orchestration from pure merge logic #8

@SmartBrandStrategies

Description

@SmartBrandStrategies

Linked feedback: ADX-007

Problem

packages/adf/src/bundler.ts currently combines manifest parsing, trigger resolution,
AST merge/transformation, token estimation, and orchestration/file loading concerns.
This raises cognitive load and couples pure transformation behavior to orchestration paths.

Evidence:

  • Manifest parsing in bundler: packages/adf/src/bundler.ts:29
  • Trigger resolution in bundler: packages/adf/src/bundler.ts:160
  • Merge and token estimation in bundler: packages/adf/src/bundler.ts:331

Scope

  • Extract manifest parsing/trigger resolution to packages/adf/src/manifest.ts.
  • Extract pure merge/token-estimation functions to packages/adf/src/merger.ts.
  • Keep bundler.ts as orchestration shell only:
    • load manifest
    • resolve module paths
    • read content
    • parse docs
    • call pure merger/evaluator

Acceptance Criteria

  • Merge utilities are pure and independently unit-tested without filesystem mocks.
  • bundler.ts no longer defines merge/token estimation internals.
  • CLI behavior for adf bundle is unchanged for existing fixtures/tests.
  • Existing bundle tests pass; add focused tests for extracted merger.ts.

Test Plan

  • pnpm run test --filter @stackbilt/adf
  • Add unit tests for:
    • duplicate-section merge behavior across content types
    • weight promotion rules
    • token estimate parity against current behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:adfADF parser/bundler/patcher packagepriority:p0Must ship this cycletype:refactorCode restructuring without behavior change

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions