Skip to content

fix(cli): say when template copy or layout expand replaced demo media - #6567

Merged
josephfarina merged 10 commits into
mainfrom
cli-spec/templates-layout/template-copy-media-receipt
Oct 5, 2026
Merged

josephfarina merged 10 commits into
mainfrom
cli-spec/templates-layout/template-copy-media-receipt

Conversation

@josephfarina

@josephfarina josephfarina commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

User impact

Anyone who scaffolds template source that carries Astryx demo images or video with astryx template <name> <path> (or template(name, {targetPath})). The copy already replaces those references, images with a neutral inline placeholder and videos with an empty source, so the output does not depend on the Astryx preview host. But the receipt never said so: template.copy was {template, outputDir, fileName, filesCopied} and printed only Copied template to app/page.tsx. The caller was never told that the page now has placeholder media to replace.

After the change the receipt carries demoMediaReplaced: how many references became placeholders, 0 when there were none. The text output adds one line naming the file, e.g. Replaced 1 Astryx demo media reference in app/page.tsx: images now show a neutral placeholder and videos have an empty source. Supply your own media there.

Problem and solution fit

  1. Why does it occur? api/template/copy/copy.mjs runs the fixture replacement and returns a receipt that predates any disclosure requirement.
  2. Why does it harm the task? An agent reads the receipt to decide what to do next. Nothing in it says the page now renders placeholders, so the agent treats the scaffold as finished.
  3. Why does that matter? The consumer ships a page with grey placeholder images or an empty video, or goes looking for media that was never installed.

The count comes from the replacement pass itself. replaceDemoMedia() in foundation/discovery/template-adapter.mjs returns the replaced source plus one count per replaced reference. A reference is replaced whole, query included, however many fixture paths its URL carries. stripTemplateAssetRefs() returns its .source, so its output is unchanged byte for byte. #6870 carries the identical adapter change, so the two PRs merge cleanly in either order.

Expected behavior and authority

docs/specs/AST-028/spec.md (authority: current), FR11: "A successful copy operation MUST tell the consumer when Astryx demonstration media was replaced and identify the generated file or replacement points they need to customize. The receipt MUST not imply that production-ready media was installed."

docs/specs/AST-017/spec.md (authority: current), DEC-4: every response field keeps "its canonical type, contract tests, applicable text output, and complete consumer documentation aligned in the same change." demoMediaReplaced has the typedef, contract tests, the text line, the FunctionDoc returns entry and the README response-type row.

docs/architecture/cli-surface.md (authority: current), INV4: "Human output is a projection of the JSON, produced only by the formatters." The text line is rendered from demoMediaReplaced through emit; nothing new is written to stderr.

Compatibility (AST-017 FR5/FR13): an additive field on template.copy; every existing field is unchanged.

Smallest restoration

  • foundation/discovery/template-adapter.mjs: replaceDemoMedia(), the existing replacement pass plus the count; stripTemplateAssetRefs() delegates to it.
  • api/template/copy/copy.mjs: the copy uses it and adds demoMediaReplaced to the receipt.
  • template.type.mjs, template.doc.mjs: the field's type and consumer description.
  • commands/template.mjs: the text projection, one line, printed only when the count is above zero.
  • foundation/response/response-types.doc.mjs and the regenerated README row: the template.copy description names the field.

Evidence

  • Reproduction before the change: astryx --json template centered-hero ./app returned {"template":"centered-hero","outputDir":"app","fileName":"page.tsx","filesCopied":1}, and the text said only Copied template to app/page.tsx, although the hero image in the written file had been replaced.
  • Result after the change: the same call adds "demoMediaReplaced": 1 and the text line above.
  • Representative unchanged path: a template with no demo media reports 0 and prints nothing new. The existing copy, overwrite and traversal tests pass unchanged.
  • Regression tests: api/template/copy/copy.receipt.test.mjs and clients/cli/commands/template.copy-receipt.test.mjs cover an image page, a video block and a no-media page, and check that JSON and text agree. template-adapter.fixture-refs.test.mjs covers the count: one reference whose query holds a second fixture path 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.
  • On main 9143f03 plus this head: the full CLI node suite (355 files, 5,581 tests), check:cli-structure, check:changesets, readme:check, both typechecks, cli-api-types-verify, eslint and prettier pass.

Scope

  • One defect is restored (AST-028 FR11, for template copy).
  • Separable contradictory or unsettled tagalongs were removed or split. The layout expand half is gone, because Remove the experimental layout command #6615 removes that command.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. replaceDemoMedia() is internal; the package API does not export it.
  • Public text and artifacts contain no internal Meta context.

Layout half restored (head cce9cd5, on main ebd939b)

#6887 restored the layout command, so the layout expand half that this PR dropped for #6615 applies again. layout expand splices template blocks and replaces their demo media without saying so (AST-028 FR11). It is restored as it was before the drop, with one change: the count comes from replaceDemoMedia(), the same pass template copy uses, so one reference counts once however many fixture paths its URL carries. layout/expand imports it through the template barrel (api/template/template.mjs), the same way the code before this PR took stripTemplateAssetRefs. A direct foundation/discovery import fails INV21. The barrel is internal; the package API exports only template() from it.

Evidence on main ebd939b plus this head: the full CLI node suite (346 files, 5,331 tests) and every gate listed above pass. With layout/expand/expand.mjs reverted, all 5 layout receipt tests fail (expected undefined to be 3).

Mechanical refresh after #6618, #6621 and #6870 (head 6c68af9, on main eb58bba)

#6618, #6585, #6621 and #6870 merged between 16:14 and 16:16 PT. This PR then conflicted with #6621 in api/template/copy/copy.mjs and with #6618 in the generated README tables. This refresh merges main and resolves both. It adds nothing new to the PR's own change:

Evidence: the refreshed tree equals the end-state tree tested before the batch (main f261d2f + #6951 + #6618 + #6585 + #6621 + #6870 + this refresh), minus #6951's one line. That tree passed every gate (readme:check, both typechecks, cli-api-types-verify, check-cli-structure, check-changesets, check-knowledge, check:repo) and the full CLI node suite (357 files, 5,650 tests).

Merge note

Squash-merged at 16:45:45 PT on 2026-10-05, pinned to head 6c68af9, as 5e7c207. All six required contexts were green on that head. The AI review's approve was still pinned to the pre-refresh head cce9cd5, because its queue had no worker online, so no fresh review could start. The merge relied on that verdict because the refresh is proven line-for-line identical in the PR's own diff (trace above), and the owner's word to merge covered it.

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.
@vercel

vercel Bot commented Sep 24, 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 5, 2026 11:29pm UTC

Request Review

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

astracat-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
⏳ Queued (for maintainers only) Oct 5, 2026, 11:20 PM UTC

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.
@josephfarina josephfarina changed the title fix(cli): say when a template copy replaced demo media fix(cli): say when template copy or layout expand replaced demo media Sep 24, 2026

@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 for restoring this disclosure in both places — the change looks ready to approve.

  • Both receipts now carry demoMediaReplaced: template.copy for the written file, and layout.expand summed over the template blocks it splices (a block referenced multiple times counts once, matching how it is spliced once). At 0 the JSON field is present and the text output stays silent.
  • The text lines name what the consumer must fix without implying media was installed — e.g. that images now show a neutral placeholder and videos have an empty source. When layout expand prints the code instead of writing it, the code is emitted unchanged and the disclosure follows as a // comment, so piped output is still valid TSX.
  • The field is projected consistently as the CLI contract requires: canonical types, function docs, README response rows, command help, and contract tests all land together, and the new receipt tests cover image, video, and no-media cases with JSON and text in agreement.

[Automated review]

Comment thread packages/cli/api/template/copy/copy.mjs Outdated
import {stripTemplateAssetRefs} from '../../../foundation/discovery/template-adapter.mjs';

/** The template-fixture namespace Astryx demo media lives under. */
const FIXTURE_NAMESPACE = '/template-assets/';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

whats this

# Conflicts:
#	packages/cli/README.md
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

josephfarina added a commit that referenced this pull request Oct 1, 2026
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 for restoring this disclosure in both places — the change looks ready to approve.

  • Both receipts now carry demoMediaReplaced: template.copy for the written file, and layout.expand summed over the template blocks it splices (a block referenced multiple times counts once, matching how it is spliced once). At 0 the JSON field is present and the text output stays silent.
  • The text lines name what the consumer must fix without implying media was installed — images now show a neutral placeholder and videos have an empty source, and the consumer is told to supply their own media. When layout expand prints the code instead of writing it, the code is emitted unchanged and the disclosure follows as a line comment, so piped output is still valid TSX.
  • The field is projected consistently as the CLI contract requires: canonical types, function docs, README response rows, command help, and contract tests all land together, and the new receipt tests cover image, video, and no-media cases with JSON and text in agreement.

[Automated review]

@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 for restoring this disclosure in both places — the shape of the change looks right, with one counting fix needed before it lands.

  • Both receipts now carry demoMediaReplaced: template.copy for the written file, and layout.expand summed over the template blocks it splices (a block referenced multiple times counts once). At 0 the JSON field is present and the text output stays silent, and when layout expand prints the code the disclosure follows as a // comment so piped output stays valid TSX. The field is also projected consistently — types, function docs, README rows, command help, and contract tests all land together.

  • One defect in how the count is computed: it is the drop in /template-assets/ substring occurrences, not the number of references replaced. A single reference whose URL contains a second fixture path — e.g. '/template-assets/a.png?f=/template-assets/b.png', which the existing transformer tests treat as one reference replaced whole, query included — reports 2 instead of 1, so the receipt would send the caller looking for a second placeholder that does not exist. No shipped template uses that form today, but the count is the point of the field, so please count the replacements actually made and add synthetic unit tests for that form and for a mixed poster-plus-video source (catalog-picked templates cannot supply either).

[Automated review]

Comment thread packages/cli/api/template/copy/copy.mjs Outdated
const output = stripTemplateAssetRefs(source);
return {
source: output,
demoMediaReplaced: countFixtureRefs(source) - countFixtureRefs(output),

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.

This counts the drop in /template-assets/ substring occurrences, not the number of references replaced. One replaced reference can contain the substring twice — e.g. '/template-assets/a.png?f=/template-assets/b.png', which the existing fixture-refs test pins as a single reference replaced whole (query included) — and this returns 2 for it (likewise for a nested-segment single reference). Please count the replacements the transformer actually makes, and add synthetic unit tests for that form and a mixed poster-plus-video source.

…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 changed the title fix(cli): say when template copy or layout expand replaced demo media fix(cli): say when template copy replaced demo media Oct 2, 2026

@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 for restoring this disclosure — the change looks ready to approve.

  • The template.copy receipt now always carries demoMediaReplaced (0 when nothing was replaced), and the text output adds one line naming the written file only when the count is above zero, so callers learn the scaffold has placeholder media to swap for their own.
  • The count now comes from the replacement pass itself — one per replaced reference, including a single reference whose URL carries a second fixture path — and synthetic tests pin that form, a poster-plus-video source, and the prose and third-party cases that must count zero.
  • The field is projected consistently as the CLI contract requires: canonical type, consumer docs, the generated README row, and the API and CLI contract tests all land together, with JSON and text in agreement.

[Automated review]

#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.
@josephfarina josephfarina changed the title fix(cli): say when template copy replaced demo media fix(cli): say when template copy or layout expand replaced demo media Oct 2, 2026

@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 for restoring this disclosure in both places — the change looks ready to approve.

  • Both receipts now carry demoMediaReplaced: template.copy for the written file, and layout.expand summed over the template blocks it splices (a block referenced multiple times counts once, matching how it is spliced once). At 0 the JSON field is present and the text output stays silent.
  • The count comes from the replacement pass itself — one per replaced reference, including a single reference whose URL carries a second fixture path — and synthetic tests pin that form, a poster-plus-video source, and the prose and third-party cases that must count zero. The text lines name what to fix without implying media was installed, and when layout expand prints the code the disclosure follows as a comment so piped output stays valid TSX.
  • The field is projected consistently as the CLI contract requires: canonical types, function docs, README rows, command help, and contract tests all land together, with JSON and text in agreement.

[Automated review]

josephfarina added a commit that referenced this pull request Oct 5, 2026
* fix(cli): print the same template source that copy writes

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.

* fix(cli): template show says how many demo media references it replaced

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.

* fix(cli): count each replaced demo media reference once

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.
Mechanical refresh. #6621 (merged as 31feb21) moved template copy's source read
before the write and wrapped the mkdir and write in ERR_WRITE_FAILED; this PR
changed that read to replaceDemoMedia(). The resolution keeps both: the
replaceDemoMedia() read before the guarded mkdir+write. #6618 (merged as
6e56409) changed the generated README tables, so they are regenerated.
@josephfarina
josephfarina merged commit 5e7c207 into main Oct 5, 2026
37 checks passed
@github-actions
github-actions Bot deleted the cli-spec/templates-layout/template-copy-media-receipt branch October 6, 2026 06:25

This branch was successfully deployed

1 active deployment
Preview — 6c68af95 Deployed Oct 5, 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