Skip to content

refactor(install): merge-safe doctrine distribution (single marker-spliced block)#14

Merged
mbanderas merged 2 commits into
mainfrom
doctrine/distribution-merge-safe
Jun 18, 2026
Merged

refactor(install): merge-safe doctrine distribution (single marker-spliced block)#14
mbanderas merged 2 commits into
mainfrom
doctrine/distribution-merge-safe

Conversation

@mbanderas

Copy link
Copy Markdown
Owner

Problem

Maestro had two doctrine-distribution channels that disagreed, and neither let a user own their repo AGENTS.md:

  • install.cjs preserved user content but, once its marker block was present, never refreshed it (skip-forever staleness).
  • sync-maestro.ps1 used Copy-Item -Force, clobbering the whole file — stripping the markers and any user content on every sync.

Change

Make scripts/install.cjs the single merge source of truth, and route the sync through it.

  • appendOnlyDoctrine now block-REPLACES in place. Absent block -> appended below existing user content; present block -> replaced between the <!-- maestro:begin --> / <!-- maestro:end --> markers, preserving everything outside. Idempotent: identical doctrine is a no-op.
  • sync-maestro.ps1 no longer overwrites files. It invokes node scripts/install.cjs --project <repo> --doctrine-only per downstream repo, so the marker-splice is the one merge path. Added --doctrine-only (splices AGENTS.md only -- no engine/adapter/wrapper/skills) and a -ListFile param for testability.

Audit findings addressed

  • R1 -- splice normalizes CRLF->LF for a canonical body (no perpetual diff); newline style is taken from the destination file.
  • R3 -- more than one begin/end marker aborts without writing (no wrong-span splice).
  • R4 -- a begin marker without a following end aborts without writing (no silent delete-to-EOF).
  • R6/R8 -- no sha256 in the marker; always-replace; no relocated clobber.
  • R7 -- markers matched by literal sentinel string, so doctrine text containing --> does not break matching.

Tests

  • install.test.cjs tests 14-18 (block-replace, idempotency, abort-on-ambiguous, abort-on-corrupt, CRLF) and 19 (--doctrine-only splices AGENTS.md and writes nothing else).
  • New sync-maestro.test.cjs smoke (real PowerShell): dry-run writes nothing, content outside the block survives a sync, re-run is byte-idempotent, missing downstream dir is non-fatal. Skips gracefully if no PowerShell is on PATH.
  • npm test (all suites), bench-verify, compress.test, and markdownlint all green locally.

A fresh-context Staff-Engineer review and an independent success verifier both returned PASS against the requirements and audit findings above.

Note: installer and doctrine are harness surfaces; this PR touches distribution logic and its tests.

…Doctrine

Replace the present-with-sentinel skip path with an in-place block splice:
absent -> append below user content; present -> replace between markers,
preserving everything outside. Splice safety: LF-normalized canonical body
(no perpetual diff), newline style taken from the destination file, abort
without writing on ambiguous (>1 begin/end) or corrupt (begin without end)
markers. Idempotent: identical doctrine is a no-op.

Makes install.cjs the single merge source of truth so a synced repo refreshes
doctrine without clobbering user-owned AGENTS.md content. Tests 14-18.
…tem clobber

sync-maestro.ps1 no longer overwrites whole AGENTS.md files. It now invokes
`node scripts/install.cjs --project <repo> --doctrine-only` per downstream repo,
making the marker-splice the single merge path: stale doctrine is refreshed in
place while user content outside the block survives. Adds a --doctrine-only mode
to install.cjs (splices AGENTS.md only — no engine/adapter/wrapper/skills) and a
-ListFile param to the sync for testability.

Tests: install test 19 (--doctrine-only splices AGENTS.md, writes nothing else,
idempotent); new sync-maestro smoke (real PowerShell: dry-run writes nothing,
content outside the block survives a sync, re-run byte-idempotent, missing dir
non-fatal; skips if no PowerShell on PATH).
@mbanderas mbanderas merged commit e6d1e4c into main Jun 18, 2026
2 checks passed
@mbanderas mbanderas deleted the doctrine/distribution-merge-safe branch June 18, 2026 02:02
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