Skip to content

fix(migrate): resolve pointer templates at call time, not module load (#355) - #381

Merged
stackbilt-admin merged 2 commits into
mainfrom
fix/355-migrate-pointer-templates
Oct 18, 2026
Merged

stackbilt-admin merged 2 commits into
mainfrom
fix/355-migrate-pointer-templates

Conversation

@stackbilt-admin

@stackbilt-admin stackbilt-admin commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Closes #355

Problem

adf-migrate.ts built POINTER_TEMPLATES at module load, from constants that adf.ts exports. The CLI loads index → doctor → adf → adf-migrate, so adf.ts was only half-initialised at that point and every template was undefined. As a result the CLI wrote the generic "This project uses [ADF]…" pointer instead of the named template:

  • charter adf migrate in the default mode: GEMINI.md, AGENTS.md, .cursorrules, copilot-instructions.md
  • charter adf migrate --replace: the same files, plus CLAUDE.md
  • bootstrap's migrate step: the same as the default mode

Unit tests that import adf-migrate directly never hit the cycle, so they passed.

Fix

The module-level table is replaced with pointerTemplateFor(baseName), which looks the template up when the pointer is written. This is the same approach as restoreTemplate in adf-vendor.ts, getPointerTemplates in adf-tidy.ts and pointerTemplatesFor in adf-compile.ts.

I checked every module that imports from ./adf (adf-compile, adf-migrate, adf-populate, adf-tidy, adf-vendor, bootstrap, doctor, score) for reads of its constants at module scope. adf-migrate was the only one. The review confirmed this with an AST scan of dist/.

Tests

  • New adf-migrate-pointer-cycle.test.ts imports ../index first. For both GEMINI.md and AGENTS.md, in the default mode and with --replace, it checks that the output starts with the named template and contains no generic pointer line. These cases fail on origin/main and pass with the fix.
  • Built CLI binary in a scratch dir: adf migrate --source GEMINI.md and --source AGENTS.md now write the named templates.
  • Full suite, run serially: 1764 pass. The 3 failures are the known Windows-only ones (bootstrap bootstrap: phases 6/7 collect warnings without printing them; absoluteAiDirArg misses Windows paths on POSIX #307, context-refresh, serve-context).

🤖 Generated with Claude Code

kovermier and others added 2 commits October 17, 2026 19:59
…#355)

adf-migrate built POINTER_TEMPLATES when it loaded, but the CLI loads it
through index -> doctor -> adf -> adf-migrate while adf.ts is still
initialising, so every template was undefined and `adf migrate --replace`
wrote the generic pointer to GEMINI.md, AGENTS.md and the rest. Look the
template up when the pointer is written, as restoreTemplate does.

The new test imports ../index first so it sees the same cycle the binary
does. No other module in the cycle reads adf.ts constants at load time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st default mode

Review of #381: the generic pointer was written in migrate's default (coexist) mode and by bootstrap's migrate step too, not only under --replace. Correct the entry and cover default mode in the cycle test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stackbilt-admin
stackbilt-admin merged commit 636563f into main Oct 18, 2026
7 checks passed
@stackbilt-admin
stackbilt-admin deleted the fix/355-migrate-pointer-templates branch October 18, 2026 01:46
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.

adf migrate writes the generic pointer for GEMINI.md/AGENTS.md: POINTER_TEMPLATES built during a circular import

2 participants