Skip to content

fix(cli): template reads ~/ as the home folder, never a folder named ~ - #12706

Closed
josephfarina wants to merge 2 commits into
mainfrom
fix/template-home-path
Closed

josephfarina wants to merge 2 commits into
mainfrom
fix/template-home-path

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

User impact

astryx template <name> <path> is often called by tools that pass arguments without a shell. A destination written ~/scratch/page.tsx then reaches the CLI as text, and the copy wrote it into a new folder literally named ~ inside the project: a stray folder the app now builds, typechecks and lints, and not the place the caller named. template --cdn ~/page.html did the same.

Problem and solution fit

  • Why does it happen? The destination check reads ~/… as a relative path, so it resolves inside the current folder.
  • Why does it matter? The caller meant their home folder. A silent write somewhere else is worse than a clear refusal: the caller cannot see that it went wrong.
  • Why does the fix close it? ~ and ~/… now name the home folder, as a shell reads them (homeRelativePath). The destination then follows the rules an absolute path already follows: inside the project it is written there; anywhere else it is refused with ERR_PATH_TRAVERSAL and the commands that work. (A ~/ path takes a scratch copy only where its absolute form would: a path in the system temp folder.) Messages still quote the path as given.

Expected behavior and authority

Record change, in architecture:cli-surface INV10, after the scratch-copy sentence (DEC-15): for astryx template <name> <path> and --cdn <path>, a destination that is ~, or starts with ~/ or ~\, names the home folder, as a shell reads it, and then follows the rules of an absolute path; a destination written that way never makes a folder named ~ in the project; reading it so is a compatible [fix]. The rule is for template only. init --to already reads ~ this way, and both now share one helper (foundation/agent-docs/folder-scope.mjs).

A folder that is really named ~ in the project is still reachable: write it as ./~/<path>. The changeset says so.

Smallest restoration

  • foundation/agent-docs/folder-scope.mjs: homeRelativePath(value, home), which only reads ~ and ~/ (or ~\), next to the folder rule init --to already applies there (absoluteFolder now calls it). It stays a leaf with no CLI imports, so astryx --version loads no new module; foundation/fs/path-safety.mjs re-exports it for the template commands.
  • api/template/copy/copy.mjs and api/template/cdn/cdn.mjs: check the expanded path, quote the given one.
  • api/template/template.doc.mjs and the command help (clients/cli/commands/template.doc.mjs, <path> and --cdn): one sentence on ~/.
  • ~\ is read as the home folder on every platform, as init --to already reads it.

No other path changes meaning (./~/x, ~other/x and a~/x stay as they were). The JSON shape is unchanged.

Evidence

  • Reproduction before the change: template kanban-board --type page '~/wb-scratch/kanban.tsx' wrote ./~/wb-scratch/kanban.tsx in the project. The three new tests fail on main.
  • Result after the change: the same call is refused with the outside-the-project message and suggestions, and writes nothing; a ~/ path that resolves inside the project is written at its place there.
  • Representative unchanged path: relative, absolute inside the project, scratch copies in the temp folder, and .. escapes behave as before (existing path-safety, template and cdn tests pass unchanged).

Scope

Components: CLI template destination

  • 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.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

  • R1 narration: none; the added INV10 sentence states what the CLI does.
  • R2 research: none in the record.
  • R3 evidence: no evidence cell changed.
  • R4 rejected alternatives: none added.
  • R5 change references: none.
  • R6 open questions: none.
  • R7 project status: none.

Testing

  • CI=1 pnpm vitest run --project node packages/cli/api/template packages/cli/clients/cli/commands/template* packages/cli/foundation/fs packages/cli/clients/cli/lib/cli-error.test.mjs packages/cli/test/golden-reads.test.mjs packages/cli/test/docs-graph.test.mjs
  • typecheck (no new errors), prettier, pnpm check:changesets, pnpm check:cli-structure

@vercel

vercel Bot commented Nov 18, 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 Nov 19, 2026 3:05pm UTC

Request Review

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

astracat-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 19, 2026, 3:03 PM UTC

@josephfarina
josephfarina marked this pull request as ready for review November 18, 2026 22:23
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 914aec9

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 63cfdfa

⏳ Building… Until it's ready, Storybook · Sandbox open the branch's previous preview.

Package size: @astryxdesign/cli 5.50 MB packed (+553 B); no new dependencies.

Current run: CI concluded cancelled; parts of this report may be missing.


Generated by PR Enrichment workflow | 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.

Approval waits on an engineering owner deciding how the CLI reads a destination that starts with ~, and one change is needed in the meantime.

Owner decision. No current rule in architecture:cli-surface says that a leading ~ in astryx template <path> or --cdn <path> names the home folder, or that the change ships as a patch [fix]; INV10a covers refusing a write outside the project, but main writes these paths inside it (./~/…), and INV10a classifies refusing or moving such inputs like any other change. An engineering owner, the author included, settles it by adding the rule (for template only or CLI-wide, with its release tier) to architecture:cli-surface in this pull request and commenting /approve-spec <full head SHA> on that head. The /approve-spec already on this head approves no record, because the pull request changes none.

Blocking

  • homeRelativePath (packages/cli/foundation/fs/path-safety.mjs:193) repeats the ~ branch of absoluteFolder in packages/cli/foundation/agent-docs/skill-places.mjs:116-119, so make absoluteFolder return homeRelativePath(value, home) ?? path.resolve(cwd, value) and keep one copy for template and init --to.

Also worth fixing

  • The astryx template --help text for <path> and --cdn (packages/cli/clients/cli/commands/template.doc.mjs:40, :82-88) does not mention ~/, which only the API doc now explains.
  • ~\ is read as the home folder on Linux and macOS too, where no shell does that and \ is a filename character.
Claims and files checked

Review mode: full; reason: no-earlier-review

Description claims:

  • On main, a ~/… destination passed without a shell is written into a folder named ~ in the project: verified; the new tests fail on main with output under ~/project/src/pages.
  • template --cdn ~/page.html did the same: verified; cdn.test.mjs:104-110 fails on main.
  • The old check read ~/… as a relative path: verified; main's copy.mjs passed the text straight to assertWithin.
  • ~ and ~/ now name the home folder, as a shell reads them: verified (path-safety.mjs:193-199); ~\ is also read as home on every platform.
  • The expanded path follows the absolute-path rules (written inside the project, a scratch copy in the temp folder, else refused with the commands that work): verified (copy.mjs:97-124, template.path-safety.test.mjs:91-136); an inside-project ~/ path is not reported as givenPath (copy.mjs:197).
  • Messages quote the path as given: verified (copy.mjs:103, :112, cdn.mjs:85).
  • INV10 confines template writes to the project or a scratch copy in the temp folder (DEC-15): verified against the record.
  • INV10a makes this a compatible fix: false; main writes these paths inside the project, and INV10a classifies refusing or moving such inputs like any other change.
  • The template command's doc names the absolute-path rules: verified (clients/cli/commands/template.doc.mjs:40); it does not mention ~/.
  • No other path changes meaning (./~/x, ~other/x, a~/x): verified (path-safety.test.mjs:113-123); ~\x changes on Linux and macOS.
  • The JSON shape is unchanged: verified; receipt and error fields are the same.
  • The new tests fail on main: verified; the three behavior tests fail on main, and the two helper tests fail because the helper is missing there.
  • After the change the call is refused with suggestions and writes nothing, and a ~/ path inside the project is written there: verified; the new tests pass.
  • Relative, absolute, temp-folder and .. paths behave as before: verified; the existing suites pass and CI test-node passed.
  • One defect is restored: not established; main's behavior met INV10 and its help text, so this is a new reading that waits on the owner rule.
  • No new public API: verified; no export, command or option changes.
  • Testing (Vitest, typecheck, Prettier, changeset and CLI structure checks): verified; CI and the changeset, CLI structure and Prettier checks pass.

Changeset claims:

  • template <name> ~/<path> reads ~/ as the home folder: verified (copy.mjs:70-71).
  • No ~ folder is made; a home path outside the project is refused with the commands that work, and one inside it is written there: verified (template.path-safety.test.mjs:91-136).
  • template --cdn reads it the same way: verified (cdn.mjs:70, cdn.test.mjs:104-110).
  • Patch [fix]: not established; it waits on the owner rule, and no migration (./~/…) is given.

Files:

  • .changeset/template-home-path.md: release tier waits on the owner rule; no migration line.
  • packages/cli/api/template/cdn/cdn.mjs: clear.
  • packages/cli/api/template/cdn/cdn.test.mjs: clear; two existing assertions are only reflowed.
  • packages/cli/api/template/copy/copy.mjs: givenPath is not reported for a ~/ path inside the project (non-blocking).
  • packages/cli/api/template/template.doc.mjs: clear; the command help lacks the matching sentence.
  • packages/cli/clients/cli/commands/template.path-safety.test.mjs: clear.
  • packages/cli/foundation/fs/path-safety.mjs: duplicates skill-places.mjs:116-119 (blocking); ~\ on Linux and macOS (non-blocking).
  • packages/cli/foundation/fs/path-safety.test.mjs: clear.

Automated review (maintainer link)

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 18, 2026
@josephfarina

Copy link
Copy Markdown
Contributor Author

Owner decision (engineering owner, covering this pull request): for astryx template <name> <path> and --cdn <path>, a destination that is ~, or starts with ~/ or ~\, names the home folder, as a shell reads it, and then follows the rules of an absolute path. A destination written that way never makes a folder named ~ in the project. Reading it so is a compatible [fix]. architecture:cli-surface INV10 states this.

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 63cfdfa

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 18, 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.

Approved pending CI: CI has not run on this head yet, and the required checks must pass before merge.

The home-folder reading of a leading ~ for astryx template <path> and --cdn is now recorded in architecture:cli-surface INV10 and approved by an engineering owner at this head, and init --to reads ~ through the same helper, so nothing blocks.

Worth a follow-up, not blocking:

  • The <path> and --cdn help and the targetPath API doc say only "a path that starts with ~/", while INV10 and the helper also read a bare ~ and a leading ~\; on Linux and macOS ~\notes/page.tsx is now refused without the help saying why.
  • A ~/ path that lands inside the project does not report givenPath (packages/cli/api/template/copy/copy.mjs:197), so the CLI's "written as its relative path" line shows for an absolute path but not for the same place written with ~/.
  • No test covers a ~\… destination or a ~/… destination in the temp folder.
Claims and files checked

Review mode: full; reason: spec-record

Description claims:

  • Without a shell, template <name> ~/… wrote into a folder named ~ in the project, and --cdn ~/… did the same: verified; the new tests fail on the base code, and a probe there writes ./~/….
  • The old check read ~/… as a relative path: verified; the base copy passed the text straight to the project guard.
  • ~ and ~/ (and ~\, on every platform) now name the home folder through homeRelativePath: verified (path-safety.mjs:193-199).
  • The expanded path follows the absolute-path rules: written inside the project, a scratch copy in the temp folder, else refused with ERR_PATH_TRAVERSAL and the commands that work: verified (copy.mjs:97-124, template.path-safety.test.mjs:91-136, probe).
  • Messages still quote the path as given: verified (copy.mjs:103, :112; cdn.mjs:85).
  • The INV10 sentence (template only, ~, ~/ or ~\, then absolute-path rules, no ~ folder, a compatible [fix]) is in the record: verified (cli-surface.md:328-332), approved by an engineering owner at this head.
  • init --to already read ~ this way and both now share one helper: verified (skill-places.mjs:116-118, skill-places.test.mjs).
  • A folder really named ~ stays reachable as ./~/<path>, and the changeset says so: verified (probe; changeset line 5).
  • The listed files make the smallest restoration (helper; copy and CDN check the expanded path; API doc and command help sentence; init --to on the helper): verified, file by file.
  • No other path changes meaning (./~/x, ~other/x, a~/x): verified (path-safety.test.mjs:113-124, probe).
  • The JSON shape is unchanged: verified; the same receipt and error fields.
  • Before the change the call wrote under ./~/…, and the three new tests fail on the base: verified with the equivalent blank tests; the two helper tests also fail there.
  • After the change the call is refused with the message and suggestions and writes nothing, and a ~/ path inside the project is written there: verified; the new tests pass.
  • Relative, absolute, temp-folder and .. paths behave as before: verified; the existing suites pass, apart from one sandbox-only temp-folder case that fails the same way on the base.
  • One defect restored, no hidden public API or default, no internal context: verified; INV10 classifies it as a [fix], the API delta is empty, and the text is clean.
  • Writing rubric: the INV10 sentence states what the CLI does and adds no status: verified.
  • Testing (Vitest, typecheck, Prettier, changeset and CLI structure checks): verified; tests pass, the CLI typecheck shows no error in a changed file, the changeset and CLI structure checks pass, and the changed lines are formatted (skill-places.mjs keeps six older unformatted spots that the base has too).

Changeset claims:

  • template <name> ~/<path> reads ~/ as the home folder: verified (copy.mjs:70-71).
  • No ~ folder is made; a home path outside the project is refused with the commands that work, and one inside is written there: verified (template.path-safety.test.mjs:91-136).
  • template --cdn reads it the same way: verified (cdn.mjs:70, cdn.test.mjs:104-110).
  • ./~/<path> reaches a real ~ folder: verified (probe).
  • Patch [fix]: verified against INV10's new sentence.

Files:

  • .changeset/template-home-path.md: clear.
  • docs/architecture/cli-surface.md: clear; owner-approved INV10 sentence, no approval line changed.
  • packages/cli/api/template/cdn/cdn.mjs: clear.
  • packages/cli/api/template/cdn/cdn.test.mjs: clear; two existing assertions only reflowed.
  • packages/cli/api/template/copy/copy.mjs: givenPath not reported for a ~/ path inside the project (non-blocking).
  • packages/cli/api/template/template.doc.mjs: names only ~/ (non-blocking).
  • packages/cli/clients/cli/commands/template.doc.mjs: names only ~/ (non-blocking).
  • packages/cli/clients/cli/commands/template.path-safety.test.mjs: clear.
  • packages/cli/foundation/agent-docs/skill-places.mjs: clear; reads ~ through the shared helper.
  • packages/cli/foundation/fs/path-safety.mjs: clear.
  • packages/cli/foundation/fs/path-safety.test.mjs: clear; no ~\ case (non-blocking).

Automated review (maintainer link)

required: false,
description:
'Where to scaffold the template, inside the project root: a relative path, or an absolute path inside the project, which is written as its relative path. An absolute path in the system temp folder (such as /tmp/dashboard) takes a scratch copy, outside the project. Any other path outside the project is refused. A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is the file to write; ' +
'Where to scaffold the template, inside the project root: a relative path, or an absolute path inside the project, which is written as its relative path. An absolute path in the system temp folder (such as /tmp/dashboard) takes a scratch copy, outside the project. Any other path outside the project is refused. A path that starts with ~/ names the home folder, as a shell reads it, and follows the same rules. A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is the file to write; ' +

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.

INV10 and homeRelativePath also read a bare ~ and a leading ~\ as the home folder, on every platform, but this help (and --cdn at line 87, and the targetPath API doc) names only ~/. On Linux or macOS ~\notes/page.tsx used to make a folder in the project and is now refused. Consider "A path that is ~, or starts with ~/ or ~\, names the home folder" (non-blocking).

@josephfarina
josephfarina force-pushed the fix/template-home-path branch from 63cfdfa to bd60bb4 Compare November 19, 2026 14:45
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 19, 2026
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec bd60bb4

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 19, 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.

Approved pending CI: CI has not run on this head, because its commit message carries [skip ci], so the required checks run only after a new push without it and must pass before merge.

The home-folder reading of a leading ~ for astryx template <path> and --cdn is recorded in architecture:cli-surface INV10 and approved by an engineering owner at this head, and init --to reads ~ through the same helper, so nothing blocks.

Worth a follow-up, not blocking:

  • The <path> and --cdn help and the targetPath API doc say only "a path that starts with ~/", while INV10 and the helper also read a bare ~ and a leading ~\; on Linux and macOS ~\notes/page.tsx is now refused without the help saying why.
  • A ~/ path that lands inside the project does not report givenPath (packages/cli/api/template/copy/copy.mjs:197), while an absolute path to the same place does.
  • No test covers a bare ~, a ~\… destination or a ~/… destination in the temp folder.
Claims and files checked

Review mode: full; reason: rebase

Description claims:

  • Without a shell, template <name> ~/… wrote into a folder named ~ in the project, and --cdn ~/… did the same: verified; the new tests fail on the base code, and running the base code writes ./~/….
  • The old check read ~/… as a relative path: verified; the base copy passed the text straight to the project guard.
  • ~ and ~/ now name the home folder through homeRelativePath: verified (folder-scope.mjs:44-50).
  • The expanded path follows the absolute-path rules: written inside the project, a scratch copy only in the temp folder, else refused with ERR_PATH_TRAVERSAL and the commands that work: verified (copy.mjs:97-124, template.path-safety.test.mjs:91-136, and a run with the temp folder inside the home folder).
  • Messages still quote the path as given: verified for the outside-project and temp-folder messages (copy.mjs:103, :112; cdn.mjs:85); the link refusal keeps quoting the resolved file, as it did before.
  • The INV10 sentence (template and --cdn only; ~, ~/ or ~\; then the absolute-path rules; no ~ folder; a compatible [fix]) is in the record: verified (cli-surface.md:328-332), approved by an engineering owner at this head.
  • init --to already read ~ this way, and both now share one helper in folder-scope.mjs: verified (folder-scope.mjs:60-62).
  • A folder really named ~ stays reachable as ./~/<path>, and the changeset says so: verified (a run, and the changeset).
  • The helper stays a leaf with no CLI imports, and path-safety.mjs re-exports it for the template commands: verified (folder-scope.mjs:16-17, path-safety.mjs:20).
  • The copy and CDN writers check the expanded path and quote the given one; the API doc and command help gain one sentence on ~/: verified.
  • ~\ is read as the home folder on every platform, as init --to already read it: verified.
  • No other path changes meaning (./~/x, ~other/x, a~/x): verified (path-safety.test.mjs:113-124, and a run).
  • The JSON shape is unchanged: verified; the same receipt and error fields.
  • Before the change the call wrote under ./~/…, and the new tests fail on main: verified with the equivalent blank template; all five new tests fail on the base code.
  • After the change the call is refused and writes nothing, and a ~/ path inside the project is written there: verified; the new tests pass.
  • Relative, absolute, temp-folder and .. paths behave as before, and the existing tests pass: verified; the existing suites give the same results on the base and the head.
  • One defect restored, no hidden public API or default, no internal context: verified; INV10 classifies it as a [fix] and no public export changes.
  • Writing rubric: the INV10 sentence states what the CLI does and adds no status: verified.
  • Testing (Vitest, typecheck, Prettier, changeset and CLI structure checks): verified; the typecheck shows only two errors the base has too, and the changed lines are formatted (one untouched line in folder-scope.mjs fails Prettier on the base too).

Changeset claims:

  • template <name> ~/<path> reads ~/ as the home folder: verified (copy.mjs:70-71).
  • No ~ folder is made; a home path outside the project is refused with the commands that work, and one inside is written there: verified (template.path-safety.test.mjs:91-136).
  • template --cdn reads it the same way: verified (cdn.mjs:70, cdn.test.mjs:104-110).
  • ./~/<path> reaches a real ~ folder: verified (a run).
  • Patch [fix]: verified against INV10's new sentence.

Files:

  • .changeset/template-home-path.md: clear.
  • docs/architecture/cli-surface.md: clear; owner-approved INV10 sentence, no approval line changed.
  • packages/cli/api/template/cdn/cdn.mjs: clear.
  • packages/cli/api/template/cdn/cdn.test.mjs: clear; two existing assertions only reflowed.
  • packages/cli/api/template/copy/copy.mjs: givenPath not reported for a ~/ path inside the project (non-blocking).
  • packages/cli/api/template/template.doc.mjs: names only ~/ (non-blocking).
  • packages/cli/clients/cli/commands/template.doc.mjs: names only ~/ (non-blocking).
  • packages/cli/clients/cli/commands/template.path-safety.test.mjs: clear.
  • packages/cli/foundation/agent-docs/folder-scope.mjs: clear; absoluteFolder reads ~ through the shared helper.
  • packages/cli/foundation/fs/path-safety.mjs: clear.
  • packages/cli/foundation/fs/path-safety.test.mjs: clear; no ~\ case (non-blocking).

Automated review (maintainer link)

josephfarina added a commit that referenced this pull request Nov 19, 2026
josephfarina added a commit that referenced this pull request Nov 19, 2026
josephfarina added a commit that referenced this pull request Nov 19, 2026
- #12895 experimental theme: a saved --only on a part styled on its own opens
  Author: @josephfarina
- #12706 fix(cli): template reads ~/ as the home folder, never a folder named ~
  Author: @josephfarina
- #12750 feat(cli): experimental icon names each match's meaning import
  Author: @josephfarina
- #12307 fix(core): keep anchored layers on screen when their trigger runs past the viewport
  Author: @josephfarina
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #12940.

@github-actions
github-actions Bot deleted the fix/template-home-path branch November 20, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — bd60bb41 Deployed Nov 19, 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