Skip to content

refactor: extract lib/ foundation layer and decompose src/#38

Merged
josstei merged 17 commits into
devfrom
impl/src-decomposition
Apr 14, 2026
Merged

refactor: extract lib/ foundation layer and decompose src/#38
josstei merged 17 commits into
devfrom
impl/src-decomposition

Conversation

@josstei

@josstei josstei commented Apr 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • New lib/ foundation layer: Extracted reusable primitives into src/lib/ — errors, validation, naming, I/O, frontmatter parsing, and generic discovery framework — each with strict contracts and comprehensive tests
  • Source decomposition: Migrated core, hooks, MCP handlers, and transforms to consume lib/ modules instead of ad-hoc implementations; removed deprecated modules (agent-names.js, atomic-write.js, file-utils.js, session-id-validator.js)
  • Generator refactoring: Extracted generation-session.js, tool-outcome.js, and registry builder helpers; simplified registry-scanner.js by ~30%
  • Layer boundary enforcement: Added scripts/check-layer-boundaries.js to prevent lib/ from importing higher layers; integrated into justfile
  • Bug fix included: Coerces LLM string numbers to integers before phase lookups in transition phase (fix: coerce LLM string numbers to integers before phase lookups in transition phase #37)

Changes

Area What changed
src/lib/errors Typed error hierarchy (MaestroError, ValidationError, IOError, DiscoveryError)
src/lib/validation Reusable validation primitives with composable validators
src/lib/naming Case conversion utilities (kebab, camel, pascal, title)
src/lib/io Safe I/O primitives (atomic write, read with fallback, directory listing)
src/lib/frontmatter Unified frontmatter parser extracted from transforms
src/lib/discovery Generic discovery framework replacing ad-hoc file scanning
src/core Removed deprecated modules, updated imports
src/mcp Migrated handlers to lib/errors and lib/validation
src/transforms Migrated to lib/ and auto-discovery
src/hooks Migrated to lib/ foundation
src/generator Extracted session, tool-outcome, and registry builders
scripts Added layer boundary checker
tests Full migration parity tests + new unit tests for all lib/ modules

Test plan

  • npm test — all existing and new unit/integration tests pass
  • node scripts/check-layer-boundaries.js — no lib/ → higher-layer imports
  • Verify generator output unchanged via just generate + diff
  • Smoke test MCP server startup

josstei added 17 commits April 13, 2026 02:07
…ator pipeline

Extract 5 shared core modules from duplicated implementations:
- frontmatter-parser: unified parsing replacing 2 separate implementations
- agent-names: table-driven name conversion replacing 4 scattered functions
- feature-blocks: configurable strict/lenient stripping replacing 2 copies
- markdown-state: session state serialization replacing 3 local functions
- file-utils: safe read utilities replacing 8+ try-catch patterns

Decompose generate.js (807->148 lines) into focused modules:
- file-writer, manifest-expander, stale-pruner, payload-builder
- registry-scanner, entry-point-expander

Replace hardcoded allowlists with build-time auto-discovered registries:
- agent-registry.json scanned from src/agents/*.md
- resource-registry.json scanned from skills/templates/references
- hook-registry.json scanned from src/hooks/logic/*-logic.js

Decompose inject-frontmatter.js (291 lines) into 3 composable transforms:
- parse-frontmatter, extract-examples, rebuild-frontmatter

Adding a new agent now requires only creating src/agents/<name>.md.
Generated output is byte-identical (zero drift). 567 tests pass.
Consolidate atomic-write, file-utils, and writeIfChanged into a single I/O module at src/lib/io with zero intra-project dependencies.

Exports: atomicWriteSync, readFileSafe, readJsonSafe, writeIfChanged, ensureDir. Contract tests cover atomicity, fallback semantics, change detection, and idempotent directory creation.
Consolidate three frontmatter boundary detection implementations and two YAML escaping implementations into one authoritative module.

Exports: parse, parseFrontmatterOnly, extractValue, escapeYaml, splitAtBoundary, parseValue, parseDoubleQuotedValue.

270 tests including parity validation against all 22 agent files.
Extract 15+ inline validation patterns from MCP handlers and session
state into composable assert functions that throw typed ValidationErrors.

Validators: assertNonEmptyArray, assertSessionId, assertAllowlisted,
assertRelativePath, assertContainedIn. All throw ValidationError from
lib/errors with descriptive messages and structured details payloads.
# Conflicts:
#	claude/src/mcp/handlers/session-state-tools.js
#	plugins/maestro/src/mcp/handlers/session-state-tools.js
#	src/mcp/handlers/session-state-tools.js
@josstei josstei changed the base branch from main to dev April 14, 2026 01:54
@josstei josstei merged commit 08e9c65 into dev Apr 14, 2026
1 check passed
@josstei josstei deleted the impl/src-decomposition branch April 14, 2026 01:55
josstei pushed a commit that referenced this pull request Apr 14, 2026
Comprehensive analysis of the Qwen adapter contract mismatch,
fabricated PR description claims, binary artifacts, and fork
divergence from the #38 refactor.

https://claude.ai/code/session_01RrDPZpKY1X3o6jX5HXKPEZ
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.

1 participant