Skip to content

feat(cli): template's outside-the-project refusal names the command that writes the path from its own folder - #12710

Closed
josephfarina wants to merge 3 commits into
mainfrom
fix/template-refusal-cd-hint
Closed

josephfarina wants to merge 3 commits into
mainfrom
fix/template-refusal-cd-hint

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

User impact

astryx template <name> <path> refuses a path outside the project and outside the system temp folder. Agents that hit it usually wanted a copy at exactly that path, often in a folder of their own beside the project. For an absolute path the refusal named two commands, write inside the project or print the source, but not the command that writes the path they named; a path that left the project through .. got the bare traversal message with no command at all. So they guessed: a shell redirect of the printed source, or a second refusal.

Problem and solution fit

  • Why does it happen? The copy is confined to the folder it runs from (architecture:cli-surface INV10), and the refusal never said that the same path is fine when the command runs from a folder above it.
  • Why does it matter? The next call is a guess, and a redirected print skips what only the copy gives: the setup notes, the receipt and the overwrite guard.
  • Why does the fix close it? Any path that leaves the project (absolute or through .., never through a link) gets the same refusal, which adds one suggestion: change to the nearest folder of the path that exists, then run the same template command with the path from there. It is named only for a Core template that no integration replaces, because outside the project the project's integrations do not load. A .. path that lands in the system temp folder is not a scratch copy; its refusal names the absolute path, which takes one. That command is inside its current folder, so it writes the named path. The command names the file the copy writes, so a folder given with a trailing separator is named by its page.tsx. No suggestion is added when only the disk's root exists. Printed, the CLI invocation is the one chosen for the folder the line moves into (spec:AST-081 FR5) and comes after the change of folder (cd <folder> && npx @astryxdesign/cli@<version> template …); in JSON the entry stays bare, like the others.

Expected behavior and authority

Record change: architecture:cli-surface DEC-20, "A refused template path names the same write from its folder" (decided by the owner; it sits beside DEC-15 and DEC-17). INV10 is unchanged: the suggested write runs inside the folder it moves into. The JSON shape is unchanged: one more {name, reason} entry in suggestions. The changeset is [feat], a new suggested command (spec:AST-017 FR7).

Smallest restoration

  • api/template/copy/copy.mjs: the refusal covers .. escapes and adds the suggestion, built with the existing commandInFolder and quoteCommandArgument; api/template/template.mjs tells it whether an integration replaces the template.
  • api/template/_adapter.mjs: nearestFolder, the folder walk, kept in the subject's adapter (INV21).
  • foundation/env/package-manager.mjs: splitCommandInFolder, which reads back the folder and command of a line commandInFolder prints (POSIX and PowerShell forms, every quote character PowerShell doubles), next to it.
  • clients/cli/lib/cli-error.mjs: such a suggestion gets the CLI invocation for its folder on the command after the change of folder.
  • docs/architecture/cli-surface.md: DEC-20.

Evidence

  • Before: the refusal names the inside-the-project copy and the print for an absolute path, and nothing for a .. path. Every new test fails on main except the three no-line guards (disk root, integration template, replaced Core template), which pass on main because it never adds the line.
  • After: the refusal also names cd <folder> && astryx template <name> ./<rest>. Running exactly that command writes the named file (tested). A trailing-separator folder is named by its file (tested). A path whose only existing folder is the disk root gets no such entry (tested). The printed line takes the invocation for the folder after cd (tested), and the folder parse round-trips every commandInFolder form (tested). A .. path gets the same commands (tested); a .. path into the temp folder names its absolute path, which then takes the scratch copy (tested). An integration template, and a Core template an integration replaces (also when asked for by package), get no such line (tested). With --overwrite and an existing file at the named path, the line keeps --overwrite and running it replaces the file, with no second refusal (tested); the place inside the project never gets --overwrite, since it is another file. Run from outside the project, the copy follows that folder's icon set, not the project's.
  • No-context agent test: a model saw only the command it ran and the refusal, and had to give its next command, 5 runs per arm, each executed. Before: 5/5 redirected the printed source into the named file. After: 5/5 ran the new suggested command, and the copy wrote the named file. Both arms succeeded on the next try; with the new line, the next try is the copy instead of a shell redirect.
  • Representative unchanged path: every other template and cli-error test passes unchanged.

Scope

Components: CLI template destination refusal

  • One change: the refusal names the write the caller asked for.
  • 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; DEC-20 states what the refusal names.
  • R2 research: none in the record; the no-context agent test is in this description only.
  • R3 evidence: no evidence cell changed.
  • R4 rejected alternatives: one, in DEC-20, one line.
  • 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/clients/cli/lib packages/cli/foundation/env
  • typecheck (no new errors), pnpm check:changesets, pnpm review:pre (0 findings)

@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 20, 2026 12:14am UTC

Request Review

@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 20, 2026, 12:39 AM UTC

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

Copy link
Copy Markdown
Contributor Author

/approve-spec 5d76d28

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 5d76d28

Storybook · Sandbox · built from this PR's head

Current run: The current CI run concluded cancelled. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

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

Changes requested: one fix is needed before this can be approved.

  • In a project that installs its own CLI, the new suggestion keeps that project's invocation after the change of folder (cd <folder> && npx astryx template blank ./dash.tsx, or pnpm exec astryx …), which does not resolve from that folder, so npx fetches the unrelated astryx package and pnpm exec fails; pick the invocation for the folder after cd (formatCliCommand(command, folder), which gives the pinned @astryxdesign/cli@<version> runner there, as global mode FR5 requires) and add a test where the project's own CLI answers.

Otherwise the change holds up: the suggested arguments write the named path from that folder, the disk-root case adds nothing, and JSON keeps the bare form. The three new tests fail on the base and pass on the head.

Claims and files checked

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

  • Claim, the refusal adds a command that writes the named path from its nearest existing folder: verified for package-runner runs (copy.mjs:119-129, the nearest-folder test); false when the project's own CLI answers (cli-error.mjs:347).
  • Claim, no such suggestion when only the disk's root exists: verified (copy.mjs:251, the disk-root test).
  • Claim, printed output puts the CLI invocation after the change of folder in the POSIX and PowerShell forms, and JSON stays bare: verified (cli-error test, JSON output), with the folder caveat above.
  • Claim, the confinement rule and the JSON shape are unchanged apart from one more name and reason entry: verified.
  • Claim, the three new tests fail on main: verified (3 failed on the base with the head's tests).
  • Claim, every other template and cli-error test passes unchanged: verified (the stated test scope: 814 passed, 7 skipped).
  • Claim, the changeset check passes: verified; typecheck and the pre-review checklist were not rerun.
  • Claim, a no-context agent test moved from 5 of 5 redirects to 5 of 5 copies: not verified (no transcripts).
  • Changeset, the refusal names the command that writes that same path, as a patch fix: the patch classification is verified; the claim is false when the project's own CLI answers, until the fix above.
  • File .changeset/template-refusal-cd-hint.md: covered by the finding.
  • File packages/cli/api/template/copy/copy.mjs: clear.
  • File packages/cli/clients/cli/lib/cli-error.mjs: the finding.
  • File packages/cli/clients/cli/commands/template.path-safety.test.mjs: clear; it has no run where the project's own CLI answers.
  • File packages/cli/clients/cli/lib/cli-error.test.mjs: clear.

Automated review (maintainer link)

@josephfarina josephfarina changed the title fix(cli): template's outside-the-project refusal names the command that writes the path from its own folder feat(cli): template's outside-the-project refusal names the command that writes the path from its own folder Nov 19, 2026
@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

Owner decision (engineering owner, covering this pull request at its current head): architecture:cli-surface DEC-18 stands as written here. When astryx template <name> <path> refuses a destination outside the project and outside the temp folder, the refusal also names a command that writes the same destination from the nearest folder on its path that exists, using the CLI command that folder would use. The command is named only for a Core template that no integration replaces.

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 437744d

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

The earlier request is resolved: the run-from-its-folder line now uses the CLI invocation for the folder after cd, and .. paths get the same refusal and commands as absolute ones. Two small follow-ups, neither blocking:

  • When a file sits where a folder of the destination should be (/work/out/notes.txt/x.tsx), the suggested cd command fails with EEXIST, so naming no command there, as for the disk's root, avoids a dead end.
  • Miss: the new command drops --overwrite, so a caller who passed it for an existing file gets a second refusal; carrying the flag into that one line keeps their choice.
Claims and files checked

Review mode: full; reason: spec-record

  • Changeset: a refused Core-template destination outside the project now comes with a command that writes it from its nearest existing folder, using that folder's CLI invocation: verified (path-safety tests; a run where the project's own CLI answers), except when a file sits on the path (first note).
  • Changeset: a .. path now gets the same commands as an absolute path: verified (.. test; the base prints only the traversal message).
  • Changeset: a .. path into the temp folder is not a scratch copy, and the refusal names its absolute path, which takes one: verified (run with scratch copies on; the PR's test skips where the temp folder holds the home folder).
  • Changeset: a [feat] patch: verified (changeset check).
  • Description: only a path that leaves the project without a link gets this refusal: verified (copy.mjs:101-102; the link tests pass unchanged).
  • Description: the line is only for a Core template no integration replaces, also when asked for by package: verified (two integration tests).
  • Description: a folder given with a trailing separator is named by its file: verified (test).
  • Description: no line when only the disk's root exists: verified (test).
  • Description: text output uses the invocation for the folder after cd, and JSON stays bare: verified (folder test; project-CLI run prints the pinned runner).
  • Description: the folder parse round-trips every printed form, PowerShell's doubled quotes included: verified (round-trip test).
  • Description: the record adds one decision beside DEC-15 and DEC-17; the confinement rule and the JSON shape are unchanged: verified (record diff; suggestions stay name and reason).
  • Description: the folder walk lives in the subject's adapter: verified (CLI structure check).
  • Description: every new test fails on main except the three no-line guards: verified (8 fail on the base, the 3 guards pass; the temp-folder case was run separately).
  • Description: running the named command writes the named file: verified (test).
  • Description: a copy made from outside the project follows that folder's icon set: verified by reading (template.mjs:286-289); not tested.
  • Description: the no-context agent test moved 5 of 5 runs from redirects to copies: not verified (no transcripts).
  • Description: every other template and cli-error test passes: verified (the stated scope: 821 passed, 8 skipped).
  • Description: no new typecheck errors: verified for the CLI's strict typecheck (the same two unbuilt-theme errors on base and head); the pre-review checklist was not rerun.
  • Description: the changeset check passes: verified.
  • File .changeset/template-refusal-cd-hint.md: clear.
  • File docs/architecture/cli-surface.md: clear.
  • File packages/cli/api/template/_adapter.mjs: first note.
  • File packages/cli/api/template/copy/copy.mjs: second note.
  • File packages/cli/api/template/template.mjs: clear.
  • File packages/cli/api/template/template-integration.test.mjs: clear.
  • File packages/cli/clients/cli/commands/template.path-safety.test.mjs: clear.
  • File packages/cli/clients/cli/lib/cli-error.folder.test.mjs: clear.
  • File packages/cli/clients/cli/lib/cli-error.mjs: clear; the earlier invocation finding is fixed.
  • File packages/cli/clients/cli/lib/cli-error.test.mjs: clear.
  • File packages/cli/foundation/env/package-manager.mjs: clear.
  • File packages/cli/foundation/env/package-manager.test.mjs: clear.

Automated review (maintainer link)

*/
export function nearestFolder(dir) {
let at = dir;
while (!isFolder(at) && path.dirname(at) !== at) at = path.dirname(at);

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.

Non-blocking: this walk steps past an entry that exists but is not a folder. For /work/out/notes.txt/x.tsx with notes.txt a file, the refusal suggests cd /work/out && astryx template blank ./notes.txt/x.tsx, which then fails with ERR_WRITE_FAILED (EEXIST). Stopping at the first existing entry and naming no command when it is not a folder (as for the disk's root) avoids that dead end.

Comment thread packages/cli/api/template/copy/copy.mjs Resolved
@josephfarina
josephfarina force-pushed the fix/template-refusal-cd-hint branch from 437744d to a01d6fd Compare November 19, 2026 23:52
@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 5fb29ad

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 20, 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, because its commits carry [skip ci], and the merge guard still requires the checks to pass.

When astryx template <name> <path> refuses a destination outside the project for a Core template, the refusal now also names the command that writes that destination from its nearest existing folder, printed with that folder's CLI invocation and keeping --overwrite. architecture:cli-surface DEC-20 is approved at this head, and the earlier --overwrite note is fixed.

  • Non-blocking: when a file stands on the path (out/notes.txt/x.tsx with notes.txt a file), nearestFolder in packages/cli/api/template/_adapter.mjs (lines 253-257) walks past it, and the suggested command then fails with EEXIST; naming no command when the nearest existing entry is not a folder avoids that dead end.
Claims and files checked

Review mode: full; reason: rebase

Claims (description):

  • On the base, an absolute path outside the project got the in-project and print commands and a .. path got only the traversal message: verified (base copy.mjs, path-safety.mjs:108).
  • Any path that leaves the project without a link gets the same refusal plus the run-from-its-folder command: verified (copy.mjs:107-108, :162-169, tests).
  • The command is named only for a Core template no integration replaces: verified (copy.mjs:132-135, template.mjs:322-324, two integration tests).
  • A .. path into the temp folder names its absolute path, which takes a scratch copy: verified (copy.mjs:123-126, :154-161, test run with scratch copies on).
  • Running the named command from its folder writes the named file: verified (path-safety test runs the same write from that folder).
  • A folder given with a trailing separator is named by the file the copy writes: verified (test).
  • No command is added when only the disk's root exists: verified (copy.mjs:288-293, test).
  • The printed line takes the CLI invocation for the folder after the change of folder, and JSON stays bare: verified (cli-error.mjs:337-344, :121-129, three tests).
  • DEC-20 is added beside the other template decisions, INV10 and the JSON shape are unchanged: verified (cli-surface.md:1288-1309, additions only).
  • The changeset is a [feat] patch: verified (check:changesets passes).
  • The folder parser reads back every form the folder command prints, POSIX and PowerShell with each doubled quote: verified (package-manager.mjs:786-805, round-trip test).
  • With --overwrite and an existing file, the line keeps --overwrite and replaces the file; the in-project place never gets it: verified (copy.mjs:139-141, :151, test).
  • A copy made from outside the project follows that folder's icon set: verified (template.mjs:296).
  • Every new test fails on the base except the three no-line guards: verified (10 fail, 3 pass with the base sources).
  • The no-context agent test (5 of 5 runs per arm): not verified, no transcripts in the pull request.
  • Every other template and cli-error test passes unchanged: verified (862 passed, none failed).
  • Typecheck adds no errors, and pre-review finds nothing: verified (two typecheck errors, both in unchanged template pages whose theme package is unbuilt here; pre-review 0 findings).

Claims (changeset):

  • The refusal names the command that writes the same destination from its nearest existing folder, with that folder's invocation: verified (as above).
  • With --overwrite, that command and the scratch-copy command keep it, and the in-project place never does: verified (copy.mjs:151, :157, :165).
  • A .. path now gets the same commands as an absolute one: verified (test).
  • A .. path into the temp folder is still not a scratch copy and is pointed at its absolute path: verified (test).

Files:

  • .changeset/template-refusal-cd-hint.md: clear
  • docs/architecture/cli-surface.md: clear (DEC-20 approved at this head)
  • packages/cli/api/template/_adapter.mjs: non-blocking note (file on the path)
  • packages/cli/api/template/copy/copy.mjs: clear
  • packages/cli/api/template/template.mjs: clear
  • packages/cli/api/template/template-integration.test.mjs: clear
  • packages/cli/clients/cli/commands/template.path-safety.test.mjs: clear
  • packages/cli/clients/cli/lib/cli-error.folder.test.mjs: clear
  • packages/cli/clients/cli/lib/cli-error.mjs: clear
  • packages/cli/clients/cli/lib/cli-error.test.mjs: clear
  • packages/cli/foundation/env/package-manager.mjs: clear
  • packages/cli/foundation/env/package-manager.test.mjs: clear

Automated review (maintainer link)

josephfarina added a commit that referenced this pull request Nov 20, 2026
josephfarina added a commit that referenced this pull request Nov 20, 2026
josephfarina added a commit that referenced this pull request Nov 20, 2026
- #12710 feat(cli): template's outside-the-project refusal names the command that writes the path from its own folder
  Author: @josephfarina
- #13002 fix(cli): doctor outside a project names the issues of an integration installed for the computer
  Author: @josephfarina
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #13045.

@github-actions
github-actions Bot deleted the fix/template-refusal-cd-hint branch November 20, 2026 06:06

This branch was successfully deployed

1 active deployment
Preview — 5fb29adf Deployed Nov 20, 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