Skip to content

fix(cli): print the same template source that copy writes - #6870

Merged
josephfarina merged 4 commits into
mainfrom
fix/cli-template-show-matches-copy
Oct 5, 2026
Merged

josephfarina merged 4 commits into
mainfrom
fix/cli-template-show-matches-copy

Conversation

@josephfarina

@josephfarina josephfarina commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

User impact

astryx template <name> (and template() from @astryxdesign/cli/api) printed a different file than astryx template <name> <path> writes. 44 of the 714 templates show demo images or video from /template-assets/, which only Astryx's own previews serve. Copy swaps those for a placeholder. Show didn't, so anyone who printed a template and pasted it got broken images. That's the normal way an agent reads a template, and it's the only way to get a template's source through the API without writing a file.

Show now prints exactly what copy writes, and it says how many demo media references it replaced, the same way #6567 makes the copy receipt say it.

Problem and solution fit

  • Why it happens. The media swap only ever lived in the copy leaf. The show leaf returns the file as it is on disk.
  • Why it hurts. A printed template is meant to be pasted, so it has to be the same file copy would write.
  • Why that matters. One template gave two different files depending on how you asked for it.

The show leaf now runs the same replacement copy runs. It goes through replaceDemoMedia, the same pass as stripTemplateAssetRefs plus a count of the references it replaced, and the count comes back as demoMediaReplaced. Without the count, show would change the source without saying so.

Expected behavior and authority

  • spec:AST-028 FR7: copying a template must drop every Astryx-owned fixture reference, and printing the source is how agents copy it. FR11 has copy disclose what it replaced, and show now does the same.
  • spec:AST-017 FR14: no CLI behavior is hidden. The replacement is documented in the function doc, the response types, and the README, and every call reports it.
  • FR4 previews still show the real media because they read the template files directly. The only place the docsite calls template() is integration blocks, and none of them use demo media.

Smallest restoration

  • api/template/show/show.mjs returns replaceDemoMedia(source), so its source is the same file copy writes.
  • replaceDemoMedia lives in foundation/discovery/template-adapter.mjs. stripTemplateAssetRefs now returns its .source, so the replaced output is unchanged. The count is one per reference the pass replaces. A URL that carries a second fixture path in its query is replaced whole and counts once, and a prose mention or third-party URL it leaves as written counts 0.
  • template.show gains demoMediaReplaced: number. It's additive, always present, and 0 when the template carried none.
  • In text mode stdout stays exactly the source, so astryx template x > page.tsx still works. The count goes to stderr in the copy receipt's words, "Replaced N Astryx demo media references: …", and nothing prints when it's 0.
  • The function doc, the response-type doc, the type, the generated README row, and the template golden read pick up the field.

Copy and skeleton don't change. Skeleton only keeps layout props, so it never carried media paths.

One side effect worth knowing. Each demo image becomes the inline placeholder copy already writes, so the printed source for those 44 templates gets longer. The worst is library (30 images), which goes from about 15 KB to 35 KB. A shorter placeholder would shrink both outputs, but that's a separate change.

Coordination with #6567

#6567 adds the same count to the copy and layout expand receipts. Its owner and I agreed on one shape: same field name, same meaning, and the same sentence with the same pluralization. Our first version counted the drop in /template-assets/ substrings, which counts one reference twice when its query carries a second fixture path. CodeBunny caught that on #6567, so both PRs now count one per replaced reference. The helper lives once, in template-adapter.mjs. If #6567 lands first with its own copy, this PR's rebase removes the duplicate, and the other way round. Git won't flag the duplicate, so that's a deliberate step.

Evidence

  • Reproduction before the change: astryx template library printed 30 /template-assets/ paths, and astryx template library app/library wrote placeholders.
  • Result after the change: show and copy return the same source for all 714 templates, and show reports demoMediaReplaced (30 for library).
  • Representative unchanged path: copy and skeleton output, and docsite previews.
  • Regression tests:
    • api/template/show/show.test.mjs compares show and copy for all 714 templates, checks that the count is above 0 exactly when the source changed, and checks a page with a demo image through template().
    • foundation/discovery/template-adapter.fixture-refs.test.mjs pins the count: a reference with a second fixture path in its query counts 1, a poster plus a video counts 2, and a prose mention, a third-party URL, or source with no fixture counts 0. The query case fails against the old substring count.
    • clients/cli/commands/template.show-media.test.mjs checks --json carries the count, text stdout equals the JSON source, stderr states the count, and nothing is said when it's 0.
    • Every one of these fails against the old show leaf, and the count and stderr checks fail when the count or the stderr line is removed.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. The one additive field, demoMediaReplaced, is listed above.
  • Public text and artifacts contain no internal Meta context.

Testing

On main at 505e3d8 with this branch applied. The branch merges main at 2982c61, and the only commit after 505e3d8 touches the docsite, so these results still hold:

  • pnpm exec vitest run packages/cli (5,561 passed, 2 expected failures)
  • pnpm check:repo (includes check:cli-structure)
  • pnpm --filter @astryxdesign/cli typecheck:strict, typecheck:json-api, typecheck:authoring, typecheck:template-docs
  • pnpm --filter @astryxdesign/cli readme:check
  • eslint on packages/cli/api/template, packages/cli/clients/cli/commands, and the changed foundation files
  • The template golden read was updated with vitest run -u and only gained "demoMediaReplaced": 0.

astryx template <name> printed the file as it is on disk, while astryx template <name> <path> swapped demo media that only Astryx previews serve for a placeholder. The show leaf now runs the same swap, so both return the same source.
@vercel

vercel Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 2, 2026 12:30am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 1, 2026
@astracat-bot

astracat-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 2, 2026, 12:33 AM UTC

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

15 of 420 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Chat Full AI Chat probe light 155,733
Chat Full AI Chat probe dark 155,005
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,229
Chat With Attachments probe dark 11,065
SideNav Resizable in AppShell probe dark 3,208
Markdown Default probe dark 897
Markdown Default probe light 897
Markdown Default neutral dark 882
Markdown Default neutral light 858

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — this fixes a real trap: printing a template and pasting it kept demo-media paths that only Astryx previews serve, while scaffolding the same template already replaced them. The two paths now return identical source for every template, previews still show the real media, and the response descriptions match the new behaviour.

No changes needed from this review.

[Automated review]

Show now replaces demo media the way copy does, so it reports the count the way #6567 has copy report it: demoMediaReplaced on template.show, and in text a stderr line in the copy receipt wording so stdout stays the exact source. The helper replaceDemoMedia sits beside stripTemplateAssetRefs in the template adapter.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — this fixes a real trap: printing a template and pasting it kept demo-media paths that only Astryx previews serve, while scaffolding the same template already replaced them. The two paths now return identical source for every template, the new demoMediaReplaced count says how many references were replaced (in JSON, and on stderr in text mode so stdout stays exactly the source), and the response type, docs, and generated README all describe the corrected behaviour. Previews, copy, and skeleton output are unchanged.

No changes needed from this review.

[Automated review]

demoMediaReplaced counted the drop in /template-assets/ substrings, so one reference whose URL carried a second fixture path counted twice. It now counts the references the replacement pass actually replaces. stripTemplateAssetRefs output is unchanged.
# Conflicts:
#	packages/cli/README.md

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — this fixes a real trap: printing a template and pasting it kept demo-media paths that only Astryx previews serve, while scaffolding the same template already replaced them. The two paths now return identical source for every template, the new demoMediaReplaced count says how many references were replaced (in JSON, and on stderr in text mode so stdout stays exactly the source), and the response type, docs, and generated README all describe the corrected behaviour. Previews, copy, and skeleton output are unchanged.

No changes needed from this review.

[Automated review]

josephfarina added a commit that referenced this pull request Oct 2, 2026
…out half

Review fix. The count was the drop in '/template-assets/' substrings, so one
reference whose query held a second fixture path counted twice. The count now
comes from the replacement pass itself (replaceDemoMedia in the template
adapter, the same code as #6870, so the two PRs merge cleanly), one per
replaced reference. copy.mjs uses it instead of its own helper.

The layout half is gone: #6615 removes the layout command, so layout expand no
longer gets a receipt field, and the changeset names template only.
@josephfarina
josephfarina merged commit eb58bba into main Oct 5, 2026
41 checks passed
@josephfarina
josephfarina deleted the fix/cli-template-show-matches-copy branch October 5, 2026 23:21
josephfarina added a commit that referenced this pull request Oct 5, 2026
…#6567)

* fix(cli): say when a template copy replaced demo media

Copying a template swaps Astryx demo images and video for placeholders, but
the receipt never said so. `template.copy` now reports `demoMediaReplaced`,
and the text output names the file whose media the consumer has to supply.

* fix(cli): say when layout expand replaced demo media

Expanding a layout splices template blocks through the same demo media
replacement as a template copy, but `layout.expand` never said so. It now
reports `demoMediaReplaced` from the copy path's shared count, and the text
output states it, as a trailing comment when the code is printed.

* fix(cli): count each replaced demo media reference once; drop the layout half

Review fix. The count was the drop in '/template-assets/' substrings, so one
reference whose query held a second fixture path counted twice. The count now
comes from the replacement pass itself (replaceDemoMedia in the template
adapter, the same code as #6870, so the two PRs merge cleanly), one per
replaced reference. copy.mjs uses it instead of its own helper.

The layout half is gone: #6615 removes the layout command, so layout expand no
longer gets a receipt field, and the changeset names template only.

* docs(cli): regenerate the README tables on current main

* fix(cli): layout expand says when it replaced demo media again

#6887 restored the layout command, so the layout half this PR dropped for
#6615 applies again: layout expand splices template blocks and replaces their
demo media without saying so (AST-028 FR11). This restores it as it was before
that drop, with one change: the count comes from replaceDemoMedia in the
template adapter, the same pass template copy uses, so one reference counts
once however many fixture paths its URL carries.

* docs(cli): regenerate the README tables on current main

---------

Co-authored-by: Joey Farina <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 62bc9351 Deployed Oct 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant