Skip to content

fix(cli): init writes agent docs every agent reads, at the project root, never in the home folder - #7497

Merged
josephfarina merged 35 commits into
mainfrom
josephfarina/init-agent-docs-one-copy
Oct 21, 2026
Merged

josephfarina merged 35 commits into
mainfrom
josephfarina/init-agent-docs-one-copy

Conversation

@josephfarina

@josephfarina josephfarina commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

User impact

astryx init writes the Astryx block that teaches coding agents how to use the CLI. With this change:

  • Every agent CLI we tested reads the block: Claude Code, Codex CLI, Gemini CLI and Copilot CLI. That holds when the agent starts at the project root or in any folder below it, and in a fresh clone of the project.
  • The block lands at the project root, even when init runs in a subfolder.
  • The block never lands where agents read it for every project: the home folder, or a settings folder in it such as ~/.claude or ~/.gemini. A project inside such a folder, such as an agent worktree, still works.
  • doctor fails when the GEMINI.md import points at an AGENTS.md that lost its block.

On main today:

  • Gemini CLI never reads the block, because it reads GEMINI.md, which init never writes.
  • In a project with a Claude file but no AGENTS.md, init writes the block only into the Claude file. Codex CLI misses it, and so does Copilot CLI when that file is .claude/CLAUDE.md.
  • Run in a subfolder, init writes into that subfolder.
  • Run in the home folder or a settings folder in it, init writes the block into the user's own ~/.claude/CLAUDE.md, or into a new ~/.codex/AGENTS.md. Every project on the machine then gets one Astryx version's rules.

Problem and solution fit

  • Why does it happen? Each agent reads different files, and init ignores that. It writes a full block into whatever agent files exist, or creates AGENTS.md, in the folder it runs in.
    • Claude Code reads CLAUDE.md and .claude/CLAUDE.md, and reads AGENTS.md only when neither exists.
    • Codex CLI reads only AGENTS.md.
    • Gemini CLI reads only GEMINI.md, unless its settings name other files.
    • Copilot CLI reads AGENTS.md, CLAUDE.md and GEMINI.md together.
  • Why does it hurt? An agent that never sees the block works without the rules and commands it carries. A block in the home folder overrides every project's own version.
  • Why does it matter? The block is the main way an agent learns the CLI, and each of these setups is common.

The fix follows one rule: no agent gets zero copies; an extra copy is the accepted cost.

  • The block lives in files the project commits, so a fresh clone works.
  • Where agents share files, one copy can't serve each of them exactly once and still reach everyone. In those cases an extra copy is accepted.

Expected behavior and authority

  • init documents that it installs the agent docs for "your project". The consumer guide says the generated file gives the agent "everything your AI needs". An agent that never gets the block falls outside that promise.
  • The writer already treats a second copy beside an import as a defect: it leaves @path import wrappers alone, and removes a block an older run expanded into one.
  • architecture:cli-surface INV10 (every write is confined) and INV13 (agent docs have one rendered source of truth) still hold. Every write stays inside the project root, and every copy of the block is the same bytes, rendered once per run.

Smallest restoration

The layout

This applies when no --agent or --agent-docs-path is given.

  • AGENTS.md holds the block, and is created when missing. Codex CLI reads nothing else. Claude Code reads it in a project without a Claude file.
  • The Claude file the project already has keeps a full copy: root CLAUDE.md, or .claude/CLAUDE.md when there is no root one.
    • Claude Code skips AGENTS.md beside a Claude file, so the copy is needed.
    • It is a full copy, not an import: Claude Code asks before following an import of a file above the folder it started in, and a headless session never asks.
    • For the same reason, the Claude file keeps the copy even when it imports AGENTS.md itself. Started in a subfolder, Claude Code reads only the copy; started at the root, it reads two.
    • When both Claude files exist, the copy goes in root CLAUDE.md, which projects commit even when they ignore .claude/ in git. A block in .claude/CLAUDE.md is removed.
    • init creates no Claude file.
    • A Claude file that is AGENTS.md under another name (a symlink) gets no copy.
  • GEMINI.md gets a one-line managed import, @./AGENTS.md, and is created when missing.
    • The import is skipped only when GEMINI.md already imports AGENTS.md, on its own line or inline. init reads imports the way Gemini CLI does: an @path at the start of the text or after whitespace, and not inside backticks.
    • It is written even when the project's .gemini/settings.json has Gemini read AGENTS.md through context.fileName. Gemini loads project settings only when it starts at the project root, so without the import, a session started in a subfolder reads no copy. A session started at the root then reads two.
  • Existing .cursorrules, .hermes.md and HERMES.md files keep a full block, as before.
  • A project with its own layout keeps it, with a block in each file. That means imports that point at a file other than AGENTS.md, or two agent files that are one file under two names.

Where the docs go

  • The project root: the nearest folder at or above the working folder whose package.json declares an @astryxdesign package.
    • If no package.json declares one, the root is the nearest folder with any package.json. If there is none at all, it is the working folder, as before.
    • The search stops at a repository root and never counts the home folder.
    • docsWritten still lists each file relative to the working folder, for example ../../AGENTS.md.
  • In the home folder, or in a settings folder in it outside a project, init writes no agent docs. It reports docsError: {kind: 'install-failed', message} and exits 0. --remove-agents still works there, to clean up a block an earlier version wrote.
    • A folder inside a settings folder belongs to a project when it, or a folder above it below the settings folder, has a package.json. Examples are the worktrees Codex keeps in ~/.codex/worktrees/ and Cursor in ~/.cursor/worktrees/. init and upgrade work there.
    • The top of a settings folder is never a project, even with a package.json there (for example one for hook scripts in ~/.claude). Agents read ~/.claude/CLAUDE.md, ~/.codex/AGENTS.md and ~/.gemini/GEMINI.md in every project.

Links outside the project

  • A file 0.7.0 never wrote, such as GEMINI.md, is skipped when it resolves outside the project. An example is a link to a shared file in a monorepo. init reports the skip in docsError, writes the rest, and exits 0.
  • A file 0.7.0 also wrote still refuses the run with path-safety and exit 1, as before.

Presets and checks

  • --agent claude and --agent all never leave a block in both CLAUDE.md and .claude/CLAUDE.md: when CLAUDE.md gets the block, a block in .claude/CLAUDE.md is removed. --agent all leaves the GEMINI.md import as it is. The --agent help and the working-with-AI guide say both. --agent-docs-path is unchanged.
  • doctor looks for the agent docs where init writes them. It fails when the GEMINI.md import points at an AGENTS.md with no block. The setup check in the CLI and in Core no longer counts that import as setup, and it looks at GEMINI.md.
  • The reminder to run init that commands print looks at the project root too, so it stops once init has run in a nested package such as functions/.
  • The setup nudge keeps one check beyond main's: outside a git repository, main looks for init's docs only in the current folder, so it also looks where init itself writes them (the project root, by the same agentDocsTargetDir rule init uses), which quiets a nested package such as functions/ whose project root already holds init's docs; inside a repository this adds nothing, and tests pin that.
  • init --remove-agents removes the block where init writes it, at the project root, and in the folder it runs in, so a block an earlier version left in that folder goes too.
  • upgrade refreshes each block where it is, the Claude file's copy included. A project moves to the new layout the next time it runs init.
  • The init help and the working-with-AI guide state each rule above, including the .claude/CLAUDE.md removal and where the project-root search stops.

Evidence

Copies of the block each agent reads

Four agent CLIs ran headless with fresh homes, against a local stub server that records the request each one sends: Claude Code 2.1.296, Codex CLI 0.162.1, Gemini CLI 0.63.0 and Copilot CLI 1.0.97.

  • Each project is a git repository. init ran at the root, and each agent then started at the root or in src/app.
  • A cell counts the copies of the block's header line in the request, as Claude Code / Codex / Gemini CLI / Copilot CLI.
  • "main" is init from main; "this branch" is this change.
Project has, before init main, root main, src/app this branch, root this branch, src/app
no agent file 1/1/0/1 1/1/0/1 1/1/1/1 1/1/1/1
CLAUDE.md 1/0/0/1 1/0/0/1 1/1/1/2 1/1/1/2
AGENTS.md and CLAUDE.md 1/1/0/2 1/1/0/2 1/1/1/2 1/1/1/2
.claude/CLAUDE.md 1/0/0/0 1/0/0/0 1/1/1/1 1/1/1/1
CLAUDE.md linked to AGENTS.md 1/1/0/1 1/1/0/1 1/1/1/1 1/1/1/1
GEMINI.md 1/1/0/1 1/1/0/1 1/1/1/1 1/1/1/1
project Gemini settings that read AGENTS.md* 1/1/1/1 1/1/0/1 1/1/2/1 1/1/1/1
CLAUDE.md that imports AGENTS.md** 1/0/0/1 1/0/0/1 2/1/1/3 1/1/1/3
AGENTS.md, and a CLAUDE.md that imports it** 1/1/0/2 0/1/0/2 2/1/1/3 1/1/1/3
.claude/CLAUDE.md that imports AGENTS.md** 1/0/0/0 1/0/0/0 2/1/1/1 1/1/1/1

* Gemini CLI 0.64.0 for this row, with context.fileName set to "AGENTS.md" or ["AGENTS.md", "GEMINI.md"].
** Claude Code 2.1.300, Codex CLI 0.162.1, Gemini CLI 0.64.0 and Copilot CLI 1.0.97 for these rows.

The counts above 1 are the accepted extra copies:

  • Copilot CLI reads AGENTS.md and root CLAUDE.md together, as on main. When that CLAUDE.md imports AGENTS.md, Copilot CLI follows the import too and reads three.
  • Claude Code started at the root reads the copy in its Claude file, and AGENTS.md again through that file's import. Started in a subfolder, it does not follow the import, so the copy is the one it reads. Without the copy it read none there: 0 in src/app.
  • Gemini CLI started at the root reads AGENTS.md through its settings, and again through the import.

All 32 mixes of AGENTS.md, CLAUDE.md, .claude/CLAUDE.md, GEMINI.md and .cursorrules: every agent read the block in all 64 cells (each mix, from the root and from src/app).

  • The 16 mixes without a root CLAUDE.md gave 1/1/1/1, and the 16 with one gave 1/1/1/2.
  • init kept the project's own text in every file, exited 0 and reported no error.

Agents follow the block

Each agent did a small task in a project whose block carried three unusual instructions:

  • end the reply with a given closing line;
  • put a given comment at the top of each new file;
  • start new component file names with a given prefix.

The test setup:

  • Agents: Claude Code 2.1.299, Codex CLI 0.162.1, Gemini CLI 0.64.0 and Copilot CLI 1.0.97, run headless with fresh homes.
  • Five layouts:
    • AGENTS.md only;
    • an existing CLAUDE.md;
    • .claude/ ignored in git, in a fresh clone;
    • a project in a Codex worktree under the home folder;
    • project Gemini settings that read AGENTS.md.
  • Each agent started at the root and in src/app. A cell passed when the agent followed all three instructions in its reply and its files.

Result: 39 of 40 cells passed. The one miss was Gemini CLI started in src/app in the project whose Gemini settings read AGENTS.md: init skipped GEMINI.md there, and Gemini doesn't load project settings from a subfolder. This change writes the import in that case too, which gives Gemini CLI one copy in src/app and two at the root (the last row of the table above).

Edge cases

Case main this branch
.claude/ ignored in git, project has CLAUDE.md; agents run in a fresh clone 1/0/0/1 1/1/1/2
CLAUDE.md that imports AGENTS.md, plus .claude/CLAUDE.md** 2/0/0/1, root and src/app root 2/1/1/3, src/app 1/1/1/3
CLAUDE.md with an inline See @AGENTS.md** 1/0/0/1, root and src/app root 2/1/1/3, src/app 1/1/1/3
The user's Gemini settings read AGENTS.md and GEMINI.md 1/1/1/1 1/1/2/1
GEMINI.md already says Follow @./AGENTS.md always. 1/1/1/1 1/1/1/1, GEMINI.md untouched
GEMINI.md links to a file outside the project 1/1/0/1, exit 0 1/1/0/1, exit 0, skip reported in docsError
.claude links to a folder outside the project, project has CLAUDE.md 1/0/0/1, exit 0 1/1/1/2, exit 0, outside folder untouched
--agent all after the default, project has AGENTS.md and CLAUDE.md 1/1/0/2 1/1/1/2
--agent claude after the default, same project 1/1/0/2 1/1/1/2
init run in functions/src, where functions/ has its own package.json without Astryx writes functions/src/AGENTS.md; agents there read 1/1/0/1 writes at the project root; agents in functions/src read 1/1/1/1
init run in ~/.gemini writes ~/.gemini/AGENTS.md writes nothing, says why, exit 0
A git project with Astryx in a Codex worktree (~/.codex/worktrees/<id>/web), init at its root 1/1/0/1, root and src/app 1/1/1/1, root and src/app
The same in a Cursor worktree (~/.cursor/worktrees/web/<id>) 1/1/0/1, root and src/app 1/1/1/1, root and src/app
AGENTS.md deleted after init, then doctor info: "No agent docs found" fail: "GEMINI.md imports AGENTS.md, which holds no Astryx block"
init, then init --remove-agents, both run in src/app removes what init wrote in src/app removes what init wrote at the project root, and a block an earlier version left in src/app

Unchanged paths

  • --agent-docs-path writes where it did.
  • The Cursor and Hermes presets write as before.
  • A folder with no package.json above it still gets the docs where init runs.

Regression tests

They fail on main; see Testing.

Compatibility

I classified this under the release compatibility spec against 0.7.0 as a compatible fix: [fix], with patch bumps for @astryxdesign/cli and @astryxdesign/core.

  • In every measured case, an agent that reads the block on main still reads it, and the agents that miss it on main read it. A few setups still leave an agent with none, as on main, such as a GEMINI.md that links outside the project; init reports that skip.
  • The init.run JSON shape is unchanged. docsError keeps its documented kinds; install-failed already allows a message. docsWritten still lists files relative to the working folder.
  • Exit codes are unchanged, with one input newly accepted: a .claude/CLAUDE.md that links outside the project and holds no block, beside a root CLAUDE.md, is no longer written. init exits 0 there, where 0.7.0 exited 1.
  • A GEMINI.md that links outside the project exits 0, as on 0.7.0, which ignored the file. This branch reports the skip in docsError, where 0.7.0 left it null.
  • In the home folder, or in a settings folder in it outside a project, init writes nothing and says why, with exit 0 and the same JSON shape. A block written there reaches every project on the machine, which is the defect this fixes. A project inside a settings folder is written as on 0.7.0, now at its root.
  • Old usage still works: --agent claude writes the full block into the Claude file, and --agent-docs-path writes where it did.
  • init --remove-agents keeps its exit codes and the init.remove JSON shape. Run in a subfolder, it also removes the block at the project root, where init now writes it; on 0.7.0 it acted on that folder alone. Each folder is checked before anything is written, and a file that links outside its folder refuses the run, as before.
  • Extra copies remain, by design, because an extra copy beats none:
    • Copilot CLI reads two copies when a root CLAUDE.md exists, as on main, and three when that CLAUDE.md imports AGENTS.md.
    • Claude Code reads two at the root when its Claude file imports AGENTS.md.
    • Gemini CLI reads two copies at the root when Gemini settings, the project's or the user's, read AGENTS.md.
  • Why [fix] and not a new default: init documents that it installs the agent docs for the project, and on main agents miss them in common setups. Placing the block where each agent reads it restores that promise without offering anything new: no flag, option, JSON field or exit code changes, and no caller opts in or migrates. The rules are recorded in the CLI surface architecture by spec(cli-surface): agent docs reach every agent from the project's own files #7539.

Follow-ups (not in this pull request)

  • Next minor: when there is no package.json at or above the working folder, init writes no agent docs and says why. Today it writes in the working folder, which this pull request keeps, because the refusal narrows an input 0.7.0 accepts.
  • init and upgrade neither refresh nor remove a block an earlier version left in a subfolder (for example src/app/AGENTS.md, from running init there), so agents started in that subfolder read it beside the root block. init --remove-agents run in that subfolder removes it.

Scope

  • One defect is restored: init's agent docs reach every agent, from files the project commits at its root, and never land where agents read them for every project.
  • 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.

Why one pull request

The home-folder and settings-folder refusal, the project-root resolution, and the per-agent layout are one rule: where init writes agent docs (architecture:cli-surface INV31). The refusal is the edge of that rule (no mode writes outside a project), the project root is where it writes inside one, and the layout is what it writes there. Any one of them alone leaves main writing agent docs by a rule INV31 does not state: resolving the project root without the refusal would walk a run in ~/.claude up to the home folder; the layout without the root would write a full AGENTS.md copy into every subfolder init runs in; the refusal alone would refuse runs the old rule wrote to. The tests exercise them together. Of about 2,585 changed lines in packages/ and the changeset, 1,373 are tests (agent-docs layout and path safety, init behavior, remove, doctor, setup nudge, upgrade); the code and docs are 1,212.

Answers to the maintainer questions

  • Is refusing the home folder and settings folders a compatible patch? Yes, by the records. architecture:cli-surface INV31 states where init writes and that no mode writes agent docs into the home folder or a settings folder in it, outside a project. INV10a classifies refusing a write outside its confined root, before anything is written, as a compatible [fix], patch-eligible under spec:AST-017 (AST-017 FR54 points to cli-surface for this class). The changeset names each refused input (the home folder itself, and the top of a dot-folder directly in it, even with a package.json), how it fails (no agent docs, docsError install-failed, exit 0 as before), and the migration (run init from the project's own folder, or add the block by hand).
  • Do the new GEMINI.md and .claude/CLAUDE.md writes follow the protections upgrade uses? No: the managed block is Astryx-owned, so spec:AST-040's protections do not apply to it (see the maintainer decision below); architecture:cli-surface INV10 still confines every write to the project.

Maintainer decision: release tier

This ships as a [fix] on the patch plan.

  • Nothing a caller relies on changes shape. The JSON result and the exit codes stay as 0.7.1 had them for every input 0.7.1 accepted. docsError keeps its existing kind values, and no field is removed or renamed.
  • The layout is the one the record prescribes. Where init writes, and what each agent file holds, is what architecture:cli-surface INV31 states: a block in AGENTS.md at the project root, a full copy in the project's Claude Code file, and a one-line import in GEMINI.md. Init writes to that layout so that every agent reads the block.
  • One write is refused, and the record classifies that as compatible. Init no longer writes agent docs into the home folder, or into the top of a dot-folder directly in it (such as ~/.claude), even when that folder has a package.json. architecture:cli-surface INV10a classifies refusing a write outside the confined root, before anything is written, as a compatible fix. The changeset names the refused inputs, says how the refusal fails (no agent docs, docsError install-failed, exit 0 as before), and gives the migration (run init from the project's own folder, or add the block by hand).
  • No user text is removed. The .claude/CLAUDE.md change removes only the Astryx-managed block between its markers, and only when root CLAUDE.md holds the same block. It never touches the rest of the file, and it deletes the file only when nothing but whitespace is left.
  • The wider --remove-agents removes only managed blocks init writes. It now also covers the project root, where init writes, as well as the folder it runs in. It removes only the managed blocks, with the same rules for what is deleted.

Maintainer decision: the managed agent-docs block

The block between the Astryx markers is Astryx-owned content. This replaces the earlier decisions on exit codes for protected skips and on upgrade and protected agent docs.

  • Init and upgrade change only the block, as 0.7.1 did. They write, refresh, and remove only the managed block in agent-doc files, whatever ignore rules or generated markers say. They never change the text around it, and they delete a file only when nothing but whitespace (or init's own heading, for a file init created) is left. A git-ignored Claude file with your notes in it gets the block, as before.
  • Every write stays inside the project. architecture:cli-surface INV10 still refuses any path outside the project. An agent file 0.7.1 wrote whose path leaves the project (for example a CLAUDE.md linked to a shared file) still fails init with exit 1. A GEMINI.md that resolves outside the project is a file only this PR writes, so it is left as it is, reported in docsError with one note, and init exits 0. That applies in the default layout and in a project's own layout.
  • Exit codes stay as in 0.7.1. The only exception is the refusals INV10a classifies as compatible, named in the changeset. No agent-doc file is skipped as "protected", so neither init nor upgrade reports one.
  • The records. architecture:cli-surface INV31 now says: "The managed block is Astryx-owned: spec:AST-040's protections cover consumer-owned content, not the block; INV10 still confines every write." spec:AST-040 FR8 points to INV31 for the block. AST-040's protections keep covering codemods and every other edit to consumer-owned content.
  • A committed copy is never lost. While root CLAUDE.md is one the project ignores, a committed .claude/CLAUDE.md copy is refreshed, not removed, so a fresh clone still gives Claude Code a copy. An extra copy is accepted (DEC-2).
  • The sandbox app installs quietly. apps/sandbox runs astryx init --features agents on every install. A test pins that a fresh install, a second install, and a machine with an old .claude/CLAUDE.md all print nothing on stderr.

Writing rubric results

Scope: the record lines this pull request changes. These are the architecture:cli-surface INV31 header clause, the ignored-root exception in INV31's Claude Code bullet, the INV31 "managed block is Astryx-owned" bullet, and the spec:AST-040 FR8 pointer sentence.

R1 narration: none. Each sentence states what init and upgrade do, or which record governs the block. None says what changed, what was proposed, or what used to happen.
R2 research: none in the records. The reasoning for the ignored-root exception (a fresh clone lacks an ignored root CLAUDE.md) is one clause inside the rule it supports.
R3 evidence: no evidence or verification cell changed. INV31's existing verification row covers the new behavior through the agent-docs, init, and upgrade tests it already names.
R4 rejected alternatives: none recorded. The exception states only the chosen behavior.
R5 change references: none. Searching the changed lines for # followed by digits, /pull/, and /issues/ finds nothing. The only references are to records (spec:AST-040, architecture:cli-surface INV31, INV10, spec:AST-017 FR16).
R6 open questions: none. The changed sections hold no open questions.

Testing

  • New and updated tests are in agent-docs.test.mjs, agent-docs.path-safety.test.mjs, init.behavior.test.mjs, init.test.mjs, remove.test.mjs, doctor.test.mjs, upgrade.test.mjs and setup-nudge.test.mjs. They cover each layout rule, Claude files that import AGENTS.md, every form of Gemini settings, links outside the project, the home and settings folders, Codex- and Cursor-shaped worktree paths, the presets, doctor, --remove-agents from a subfolder and the reminder to run init. Run against main's code, with the new exports stubbed so the test files load, 68 of them fail.
  • Gates pass: the CLI suite (392 files: 6,341 passed, 2 expected failures), typecheck (JSON API, authoring, strict, template docs), the packaged type check, ESLint on the changed files, pnpm check:repo, the copyright, README and exports checks, Core's postinstall test, and the build.

Overlapping pull requests

Whichever lands second is updated onto the other.

… never in the home folder

The default writes the agent-docs block to AGENTS.md and a managed one-line
import of it to GEMINI.md. In a project with a CLAUDE.md or .claude/CLAUDE.md,
it also writes the block to .claude/CLAUDE.md, never root CLAUDE.md: Claude
Code skips AGENTS.md there and does not follow an import from a subfolder
session without asking, and Copilot CLI reads root CLAUDE.md beside AGENTS.md.
Each tested agent then reads the block once, from the root or a subfolder.

Init run from a subfolder writes at the nearest folder with a package.json,
within its repository and never the home folder. No mode writes agent docs
into the home folder; init reports install-failed there and exits 0.
@vercel

vercel Bot commented Oct 13, 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 21, 2026 1:37pm UTC

Request Review

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

astracat-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 21, 2026, 2:04 PM UTC

@github-actions

github-actions Bot commented Oct 13, 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

40 of 486 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
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
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,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 20 more.


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

…codes

- The Claude Code copy goes in the Claude file the project already has:
  root CLAUDE.md, else .claude/CLAUDE.md. Many projects ignore .claude/
  in git, so a new .claude/CLAUDE.md left a fresh clone with no copy.
  When both exist, root CLAUDE.md holds it. Init creates no Claude file.
- GEMINI.md gets no import when it already imports AGENTS.md, inline
  included, or when the project's Gemini settings read AGENTS.md.
- A GEMINI.md that resolves outside the project is skipped and reported;
  the rest is written and init exits 0, as before.
- The project root is the nearest package.json that declares an Astryx
  package, else the nearest package.json, else the folder init runs in,
  as before. The home folder and the settings folders in it are refused.
- --agent claude and --agent all never leave a block in both Claude
  files, and --agent all keeps the GEMINI.md import.
- doctor looks for the docs where init writes them. It fails, and the
  setup check reads not set up, when only the GEMINI.md import of an
  AGENTS.md without a block is left.
@josephfarina josephfarina changed the title fix(cli): init writes agent docs once per agent, at the project root, never in the home folder fix(cli): init writes agent docs every agent reads, at the project root, never in the home folder Oct 13, 2026
josephfarina added a commit that referenced this pull request Oct 13, 2026
init refused every folder below a settings folder in the home folder, so
a project in an agent worktree (~/.codex/worktrees/<id>/<repo>,
~/.cursor/worktrees/<repo>/<id>) got no agent docs, and upgrade could not
refresh a block there. Now only the home folder itself, and a folder in a
settings folder that belongs to no project there, are refused. A folder
below the settings folder with a package.json at or above it is a
project. The top of a settings folder stays refused even with a
package.json, because agents read the files there in every project.

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

This is a careful, well-tested change, but approval waits on a maintainer decision. No current spec covers the new default agent-docs layout for astryx init: always writing AGENTS.md, the Claude copy and .claude/CLAUDE.md removal, the created GEMINI.md import, writing at the resolved project root, and refusing the home folder and dot-folders in it. A maintainer needs to provide or identify the governing spec for it and settle whether it ships as a [fix] patch. Separately, please fix these:

  • The per-command setup nudge still checks only the working folder, so after init in a nested package such as functions/ it keeps asking for init, and re-running it there cannot clear it.
  • The --agent help and the working-with-ai guide still say all covers every existing agent doc, and do not mention that claude and all now remove the block from .claude/CLAUDE.md.
  • When root CLAUDE.md imports AGENTS.md and .claude/CLAUDE.md exists, the copy goes to .claude/CLAUDE.md, so Claude Code reads the block twice.

[Automated review]

Comment thread packages/cli/api/init/run/run.mjs Outdated
// The docs belong at the project root, not in the subfolder init ran in;
// with no project above, they go where init ran, as before. Explicit
// --agent-docs-path entries stay relative to where init ran.
const root = resolveAgentDocsRoot(cwd) ?? cwd;

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.

Init now writes at this resolved root, but the per-command setup nudge in clients/cli/index.mjs (lines 548–551) still calls isAstryxInitialized(cwd) only. In a nested package such as functions/ (its own package.json, no Astryx), every text command keeps printing "Next step: run … init", and re-running init there cannot clear it. Checking resolveAgentDocsRoot(cwd) ?? cwd there as well, as doctor now does, would keep the two in step.

const existing = discoverAgentDocs(targetDir);
// Inject into all existing files, create defaults for each tool. GEMINI.md
// is left out: the default keeps a one-line import of AGENTS.md there.
const existing = discoverAgentDocs(targetDir).filter(p => p !== GEMINI_MD);

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.

--agent all now leaves GEMINI.md out here. With --agent claude or all, the block is also removed from .claude/CLAUDE.md when CLAUDE.md gets it. The --agent option text in clients/cli/commands/init.doc.mjs still says "all (every existing agent doc, …)", and the guide's Manual options in assets/docs/working-with-ai.doc.mjs say "every agent file present", so neither help nor the guide describes these changes.

// already holds the block.
const claudeCopy = aliases.has(CLAUDE_MD)
? null
: ([CLAUDE_MD, CLAUDE_DIR_MD].find(p => present.has(p) && !wrappers.has(p)) ?? null);

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.

When root CLAUDE.md imports AGENTS.md and .claude/CLAUDE.md exists, this gives the copy to .claude/CLAUDE.md. Claude then reads the block through CLAUDE.md → AGENTS.md and again from .claude/CLAUDE.md, which the installAgentDocs comment and the changeset say should not happen. Treating a root wrapper or alias of AGENTS.md as already holding the copy, so .claude/CLAUDE.md is stripped, would fix it.

init skipped GEMINI.md when the project's .gemini/settings.json pointed
Gemini CLI at AGENTS.md. Gemini loads project settings only when it
starts at the project root, so a session started in a subfolder read no
copy of the block. Write the import whatever the settings say, and skip
it only when GEMINI.md already imports AGENTS.md. Started at the root
with such settings, Gemini reads two copies: a duplicate beats none.
… follow init

- The Claude Code file the project has, root CLAUDE.md else
  .claude/CLAUDE.md, holds the copy even when it imports AGENTS.md:
  Claude Code does not follow that import in a session started in a
  subfolder, so without the copy it read none there. A refresh keeps
  and updates that copy instead of removing it.
- The reminder to run init that commands print looks at the project
  root too, so it stops once init has run in a nested package.
- The --agent help and the working-with-AI guide say that all skips
  GEMINI.md, and that claude and all remove the block from
  .claude/CLAUDE.md when CLAUDE.md gets it.

@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 a maintainer decision: no current spec covers the new default agent-docs layout for astryx init (always writing AGENTS.md, the Claude copy and the .claude/CLAUDE.md removal, the GEMINI.md import, writing at the resolved project root, and refusing the home folder and dot-folders in it). A maintainer needs to provide or identify the governing spec for it, for example by approving the rules drafted in #7539, and settle whether it ships as a [fix] patch and whether AST-040's consumer-file protections apply to the new GEMINI.md and .claude/CLAUDE.md edits. Separately, please:

  • make init --remove-agents run from a subfolder remove what init wrote at the project root, or say in its help which folder it acts on;
  • state in the init help and the working-with-AI guide that the default removes a block from .claude/CLAUDE.md when root CLAUDE.md exists, and that the project-root search stops at a repository root;
  • rebase onto main, where #7262 and #6216 now conflict with this branch.

[Automated review]

Comment thread packages/cli/api/init/run/run.mjs Outdated
// The docs belong at the project root, not in the subfolder init ran in;
// with no project above, they go where init ran, as before. Explicit
// --agent-docs-path entries stay relative to where init ran.
const root = resolveAgentDocsRoot(cwd) ?? cwd;

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.

Init now writes at this resolved root, but init --remove-agents still calls removeAgentDocs(cwd) in api/init/remove/remove.mjs. After init in src/app writes ../../AGENTS.md and ../../GEMINI.md, init --remove-agents in src/app prints "Nothing to remove: no Astryx agent-docs block was found." and leaves both files, where main removed what init wrote. Resolving the same root in remove, or naming the folder it acts on in the option text and message, would keep the pair in step.

'getting-started steps); the theme feature also writes an annotated theme template.',
'agents, and CI). By default it writes the agent-docs block, including guidance ' +
'from configured integrations, to AGENTS.md and to the Claude Code file the project ' +
'has (CLAUDE.md, else .claude/CLAUDE.md), and a one-line import of AGENTS.md to ' +

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.

The default also removes a managed block from .claude/CLAUDE.md whenever root CLAUDE.md exists, but this description and the working-with-AI guide only say where the copy goes; the guide states the removal for --agent claude and all alone. The project-root sentence below also leaves out that the search stops at a repository root. Both are automatic behavior that help and the manifest should state.

@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: the agent-docs layout, the project-root search and the home-folder refusal match architecture:cli-surface INV31, and the earlier help and Changeset gap for a root CLAUDE.md is fixed, but that rewrite dropped one case from astryx init --help. When root CLAUDE.md is git-ignored and .claude links outside the project with a CLAUDE.md that only imports AGENTS.md, init skips it with a note and exits 0 (as the path-safety tests pin), yet the exit-0 entry in init.doc.mjs no longer lists that among its five soft cases. Please restore "or a block-less import of an existing AGENTS.md" in the ignored-root clause, or widen the Claude Code file case to cover .claude/CLAUDE.md beside a root one, ideally with a help assertion so it stays listed.

[Automated review]

{
code: 0,
when: 'success, including agent docs that could not be written for a reason other than a path escape (reported as docsError)',
when: "success, including agent docs left unwritten in five soft cases, each reported as docsError with one note: running in the home folder, or in a settings folder in it outside a project; a GEMINI.md that resolves outside the project; when init runs below the project root, a project-root agent file that resolves outside the project; the project's Claude Code file (root CLAUDE.md, or .claude/CLAUDE.md when there is no root one) when it resolves outside the project and is a block-less import of an existing AGENTS.md, which 0.7.1 left alone; and a .claude/CLAUDE.md that resolves outside the project and that 0.7.1 did not write: beside a CLAUDE.md the project ignores, the one --agent claude adds; with --agent claude beside a CLAUDE.md, one whose block it would remove",

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 list now misses one skip the head makes. While root CLAUDE.md is git-ignored, a committed .claude/CLAUDE.md gets a copy too; when .claude links outside the project and its CLAUDE.md only imports an existing AGENTS.md, init skips it with a docsError note and exits 0 (pinned in agent-docs.path-safety.test.mjs, "skips a linked-outside block-less import of an existing AGENTS.md"). The fourth case covers .claude/CLAUDE.md only when there is no root CLAUDE.md, and the fifth now names only the copy --agent claude adds, so this shape is in neither; the previous wording ("the one --agent claude adds or a block-less import of an existing AGENTS.md") covered it. Restoring that clause, or widening the fourth case to any Claude Code file that holds a copy, fixes it.

…elp; pin every soft exit-0 case

Round 11 dropped "or a block-less import of an existing AGENTS.md" from the
ignored-root clause of init's exit-0 help: with root CLAUDE.md ignored and
.claude linked outside, a .claude/CLAUDE.md that only imports an existing
AGENTS.md is skipped with a note and exit 0. Restored. A new test checks
that the help names every soft exit-0 case the path-safety tests pin.

@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: the agent-docs layout, the project-root search and the home-folder refusal match architecture:cli-surface INV31, and the earlier gap in astryx init --help is fixed and now pinned by a test. One exit-code regression remains: astryx init --remove-agents run below the project root now exits 1 with ERR_PATH_TRAVERSAL and removes nothing when a project-root agent doc that holds a block links outside the project (for example a monorepo package whose CLAUDE.md links to the repository's), where 0.7.x exits 0, although the Changeset says exit codes are unchanged. Please skip that root file with a note when run below the root, as init already does when installing, and pin the case in remove.test.mjs.

[Automated review]

export function removeProjectAgentDocs(cwd) {
const root = agentDocsTargetDir(cwd);
const dirs = realDir(root) === realDir(cwd) ? [cwd] : [root, cwd];
for (const dir of dirs) assertRemovableWithin(dir);

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.

Run below the project root, this refuses the whole removal when a project-root agent doc that holds a block links outside the project (for example apps/web/CLAUDE.md linked to ../../CLAUDE.md): the head exits 1 with ERR_PATH_TRAVERSAL and leaves the working folder's block, where 0.7.x removed it and exited 0. Install skips the same file below the root (refuseEscapes: sameFolder(targetDir, cwd) in run.mjs); skipping it here with a note, and keeping exit 0, would keep 0.7.x's exit code for this input.

Comment thread .changeset/init-agent-docs-one-copy.md Outdated
- The managed block is Astryx-owned (`architecture:cli-surface` INV31): init and `astryx upgrade` write, refresh, and remove only the block, whatever ignore rules or generated markers say, as 0.7.1 did, and never change the text around it. Every write stays inside the project (INV10): run in the folder 0.7.1 wrote, an agent file 0.7.1 wrote there whose path leaves the project still refuses the run with exit 1. The project's Claude Code file (root `CLAUDE.md`, or `.claude/CLAUDE.md` when there is no root one) that resolves outside the project and is a block-less import of an existing `AGENTS.md`, which 0.7.1 left alone, is skipped and reported in `docsError` with one note, and init exits 0. Run from a folder below the project root, where 0.7.1 wrote in that folder instead, a project-root file whose path leaves the project is skipped and reported in `docsError` with one note, the rest is written, and init exits 0.
- While root `CLAUDE.md` is one the project ignores, by its own ignore files or by those from the repository root down (a monorepo's root `.gitignore`), a `.claude/CLAUDE.md` the project commits gets the copy too, on the first run as on later ones, and `--agent claude` and `--agent all` write it there, so a fresh clone still gives Claude Code a copy. Such a copy that resolves outside the project refuses the run with exit 1 where 0.7.1 wrote it too; one 0.7.1 did not write (the one `--agent claude` adds, or a block-less import of an existing `AGENTS.md`) is skipped and reported in `docsError` with one note, and init exits 0. So is a `.claude/CLAUDE.md` whose block `--agent claude` would remove beside a `CLAUDE.md`, since 0.7.1's `claude` preset wrote only `CLAUDE.md` there. Beside a committed root `CLAUDE.md`, with `.claude` linked outside the project, three cases that 0.7.1 refused now exit 0 with nothing written: the default with a `.claude/CLAUDE.md` of plain text, and `--agent all` with one of plain text or a block-less import of `AGENTS.md`. 0.7.1 wrote that `.claude/CLAUDE.md`; now root `CLAUDE.md` holds the copy and the linked file gets none, so no write leaves the project and none needs refusing. In a project that keeps its own layout, a `GEMINI.md` that imports no agent file now gets a copy, as the other agent files do.
- The copy in `.claude/CLAUDE.md` is removed only once root `CLAUDE.md` holds the same block, and only the managed block between its markers: the rest of the file stays, and the file is deleted only when nothing but whitespace is left. `astryx init --remove-agents` deletes a file it created only when nothing but whitespace or init's own heading is left; 0.7.0 also deleted a file whose remaining text had a heading and any line with the word "guidance".
- `astryx init --remove-agents` removes the block at the project root, where `init` writes it, and in the folder it runs in. Run from a subfolder, it removes what `init` wrote at the root, and a block an earlier version left in that subfolder. Exit codes and the JSON shape are unchanged.

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.

Not true for one input yet: run in a subfolder while a project-root agent doc that holds a block links outside the project, --remove-agents now exits 1 where 0.7.x exits 0. Either keep exit 0 there (see the comment on removeProjectAgentDocs) or name it here as a newly refused input with its migration.

…e linked outside the project, with a note

Below the project root, a project-root agent file holding a block that
resolves outside the project (apps/web/CLAUDE.md -> ../../CLAUDE.md)
refused the whole removal with ERR_PATH_TRAVERSAL, leaving the working
folder's block; 0.7.x touched only that folder and exited 0. It is now
left as it is with a Note and the rest is removed, exit 0, as install does
below the root. At the root, and for a file in the working folder, an
escape still refuses the run. The --remove-agents help and the changeset
say so. Tests: the workspace-member case below the root; the same link at
the root still refuses.

@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: the agent-docs layout, the project-root search and the home-folder refusal match architecture:cli-surface INV31, and the previous astryx init --remove-agents exit-code regression is fixed and pinned by a test. Two small fixes remain:

  • In a project rooted directly in a home dot-folder (for example ~/.dotfiles), astryx upgrade --apply now leaves the agent-docs block stale, reports agentDocs.action: "error" and advises running init, which refuses there too; please name this refusal in the Changeset (the input, how it fails and the migration, as INV10a asks), have upgrade print the real reason, and pin it in upgrade.test.mjs.
  • packages/cli/api/init/init.doc.mjs still lists ERR_PATH_TRAVERSAL for a project-root file that removeAgents now leaves as it is, with a note, when run below the root; please update that entry.

[Automated review]

Comment thread .changeset/init-agent-docs-one-copy.md Outdated
- Claude Code skips `AGENTS.md` in a folder that has a `CLAUDE.md` or `.claude/CLAUDE.md`, so the Claude Code file the project already has keeps a full copy: root `CLAUDE.md`, else `.claude/CLAUDE.md`. It keeps the copy even when it imports `AGENTS.md`, because Claude Code does not follow that import in a session started in a subfolder; started at the root, Claude Code then reads two. When both exist, the copy goes in root `CLAUDE.md`, which projects commit even when they ignore `.claude/`, and a block in `.claude/CLAUDE.md` is removed. Init creates no Claude file. `astryx upgrade` refreshes every copy.
- Gemini CLI reads only `GEMINI.md`: init adds a one-line import, `@./AGENTS.md`, creating `GEMINI.md` when it is missing. It adds none when `GEMINI.md` already imports `AGENTS.md`, inline or on its own line. It adds the import even when the project's `.gemini/settings.json` has Gemini read `AGENTS.md` through `context.fileName`: Gemini loads those settings only when it starts at the project root, so a session started in a subfolder would otherwise get no copy. Started at the root, Gemini then reads two.
- The project root is the nearest folder at or above where init runs whose `package.json` declares an `@astryxdesign` package, else the nearest with any `package.json`. The search stops at a repository root and never counts the home folder. With no `package.json` found, init writes where it runs, as before. `docsWritten` still lists each file relative to where init ran, for example `../../AGENTS.md`.
- In the home folder, or in a settings folder in it such as `~/.gemini` or `~/.claude` outside a project, init writes no agent docs, reports `docsError` as `install-failed` with the reason, and still exits 0. This is a compatible fix under `architecture:cli-surface` INV31 (where init writes, and that no mode writes agent docs into the home folder or a settings folder in it) and INV10a (a refusal of a write outside its confined root, made before anything is written). The refused inputs: the home folder itself, and the top of a folder of the home folder whose name starts with a dot (every such folder is a settings folder), even when it holds a `package.json`; a folder below it with its own `package.json` is a project. How it fails: no agent docs are written, `docsError` is `install-failed` with the reason, and the exit status stays 0, as before. Migration: run `astryx init` from the project's own folder, or add the block to the file by hand. A project inside a settings folder, such as an agent worktree in `~/.codex/worktrees/` or `~/.cursor/worktrees/`, is set up normally, and `astryx upgrade` refreshes it. Agents read the files in those folders in every project. Run `astryx init --remove-agents` in the home folder to remove a block an earlier version wrote into `~/.claude/CLAUDE.md`.

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 names only init's refusal, but the same guard (assertAgentDocsTarget at the top of installAgentDocs) now also stops astryx upgrade --apply from refreshing a block in the home folder or a home dot-folder outside a project. In a project rooted at ~/.dotfiles, 0.7.x refreshed AGENTS.md; this head leaves it stale with agentDocs.action: "error", and line 10 still says "astryx upgrade refreshes every copy". INV10a asks the Changeset to name each newly refused input, how it fails, and the migration.

const written = installAgentDocs(cwd, {
onlyReplace: true,
renderedBlock,
// A GEMINI.md that resolves outside the project is left as it is.

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.

installAgentDocs can now throw AgentDocsHomeError here, which the catch below turns into "Could not refresh agent docs. Run … init --features agents to update them manually." That init writes nothing in the same folder, so the advice loops. Printing the AgentDocsHomeError message (and pinning the case in upgrade.test.mjs) would tell the person why the block stays as it is.

Comment thread packages/cli/api/init/init.doc.mjs Outdated
{
code: 'ERR_PATH_TRAVERSAL',
when: 'the template output path resolves outside cwd (for example through a symlinked src directory), or, with removeAgents, a managed agent-docs file resolves outside cwd through a symlink',
when: 'the template output path resolves outside cwd (for example through a symlinked src directory), or, with removeAgents, a managed agent-docs file at the project root or in cwd resolves outside that folder through a symlink',

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.

Since this revision, run below the project root, a project-root agent file that resolves outside the project is left as it is with a note and init({removeAgents: true}) resolves with removed: true; only a file in cwd, or at the root when run there, rejects. Suggest: "with removeAgents, a managed agent-docs file in cwd, or at the project root when run there, resolves outside that folder through a symlink (run below the root, a project-root file is left as it is with a note)".

…instead of pointing at init; init's ERR_PATH_TRAVERSAL entry matches removal below the root

- In a project at the top of a home settings folder (~/.dotfiles with a
  package.json), upgrade --apply cannot refresh the block (INV31), and its
  warning said to run init --features agents, which refuses the same
  folder. It now names the folder and why, and says to move the project or
  update the block by hand. agentDocs.action stays error. The changeset
  names the refusal in INV10a form (input, failure, migration), and its
  "upgrade refreshes every copy" names the exception.
- api/init/init.doc.mjs: ERR_PATH_TRAVERSAL with removeAgents is for a file
  in cwd, or at the project root when run there; below the root such a file
  is left with a note.
Test: upgrade --apply in ~/.dotfiles leaves the block and prints the
reason, without init.

@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: the agent-docs layout, the project-root search and the home-folder refusal match architecture:cli-surface INV31, and the previous round's upgrade message and API-doc fixes are in. Two small fixes remain:

  • astryx init --agent-docs-path notes/AI.md run from the home folder now writes nothing, although the file lands in an ordinary subfolder and the Changeset says explicit paths work as before; please apply the home-folder check to each file's folder rather than to the working folder, with a test.
  • astryx upgrade without --apply, in a project rooted at the home folder or a home dot-folder, still reports would-refresh and says to re-run with --apply, which then refuses; please have the dry run report the same refusal, with a test.

[Automated review]

Comment thread packages/cli/api/init/run/run.mjs Outdated
// --agent-docs-path entries stay relative to where init ran.
const root = agentDocsTargetDir(cwd);
const targetDir = paths ? cwd : root;
assertAgentDocsTarget(targetDir);

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.

With --agent-docs-path, targetDir is the working folder, so this refuses every explicit path given from the home folder: cd ~ && astryx init --agent-docs-path notes/AI.md now writes nothing (the base wrote ~/notes/AI.md), while the same file is written when init runs in ~/notes. INV31 refuses only writes into the home folder or a settings folder in it, and the Changeset says --agent-docs-path writes where init runs, as before. Checking each resolved file's folder instead (refusing AI.md or .claude/CLAUDE.md given from ~, keeping notes/AI.md), with a test beside "refuses an explicit path", would fix it.

logger.warn(
`Could not refresh agent docs. Run \`${formatCliCommand('astryx init --features agents')}\` to update them manually.`,
);
if (err instanceof AgentDocsHomeError) {

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 now explains the refusal on --apply, but the dry run never reaches it: prepareAgentDocsRefresh (line 344) still reports would-refresh and prints "Re-run with --apply to refresh (AGENTS.md)" in the same project. Checking assertAgentDocsTarget(cwd) there and reporting error with this reason would keep the preview and the apply step in agreement.

…pgrade's dry run reports the home-folder refusal

- init --agent-docs-path from the home folder refused every path, because
  the home check ran on the working folder: cd ~ && init --agent-docs-path
  notes/AI.md wrote nothing, where 0.7.x wrote ~/notes/AI.md. Each path's
  own folder is checked now, before anything is written: notes/AI.md is
  written; AI.md or .claude/CLAUDE.md from the home folder is refused with
  the note, as before.
- upgrade without --apply, in a project at the home folder or the top of a
  settings folder, reported would-refresh and "Re-run with --apply", which
  then refused. It now reports agentDocs.action error with the same reason
  --apply prints.
- The --agent-docs-path help and the changeset say so.
Tests: an explicit path into a plain folder of the home folder is written,
directly and through init; one in the home folder, at the top of a settings
folder, or among several paths is refused with nothing written; the dry run
in ~/.dotfiles reports the refusal.

@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: the agent-docs layout, the project-root search and the home-folder refusal match architecture:cli-surface INV31, and the previous round's explicit-path and dry-run fixes are in. Three fixes remain:

  • A .claude/CLAUDE.md that git tracks loses its copy, or never gets one, when an unanchored CLAUDE.md line in .gitignore also matches it, so a fresh clone gives Claude Code no copy; please count tracked files as committed in claudeDirKeepsCopy, with a test.
  • In the home folder (with a stray package.json) or a project at the top of a home dot-folder such as ~/.dotfiles, the setup nudge, upgrade's "No Astryx agent-docs block found" line and doctor's agent-docs fix still say to run init, which writes nothing there; please skip the nudge there and give the refusal and its migration instead, with tests.
  • The new --agent-docs-path help says only a path directly in the home folder or at the top of a settings folder is refused, but any folder in a settings folder outside a project is (for example hooks/AI.md run in ~/.claude); please reword it to match.

[Automated review]

*/
function claudeDirKeepsCopy(targetDir) {
if (!rootClaudeIgnored(targetDir)) return false;
return !ignoredHere(targetDir, CLAUDE_DIR_MD, false);

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 treats any .claude/CLAUDE.md an ignore pattern matches as uncommitted, but Git and Mercurial apply ignore rules only to untracked files. With CLAUDE.md in .gitignore and a tracked .claude/CLAUDE.md, init strips its block (or adds none on a first run), so a fresh clone, which lacks the ignored root CLAUDE.md, gives Claude Code no copy (INV31: "every agent CLI reads at least one copy … from files the project commits"). Counting a tracked file as committed, or keeping the copy whenever tracking can't be read, would fix it.

// repository the walk above already reaches it (the root never lies
// above the repository root), so this changes nothing there; outside a
// repository the walk checks only cwd, and this finds the root.
if (isAstryxInitialized(agentDocsTargetDir(cwd))) return;

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.

In the home folder (with a stray package.json) or at the top of a home dot-folder such as ~/.dotfiles, this nudge still says to run init, which now writes nothing there, so it prints again on every command. Skipping it when assertAgentDocsTarget(agentDocsTargetDir(cwd)) throws would stop the loop; upgrade's missing-docs line (api/upgrade/_adapter.mjs:330-335) and doctor's agent-docs fix (api/doctor/doctor.mjs:623) need the same check.

description:
'Explicit file path(s) for agent docs, inside the project; takes precedence over --agent. ' +
'If any path is outside the project, no agent docs are written and the command exits 1. ' +
'A path directly in the home folder, or at the top of a settings folder in it such as ~/.claude, is refused with a note (exit 0), and nothing is written. ' +

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.

The code refuses every folder in a home settings folder that no package.json makes a project, not only its top: --agent-docs-path hooks/AI.md run in ~/.claude, and .claude/agents/AI.md run in the home folder, are refused too. Suggest: "A path in the home folder itself, or in a settings folder in it outside a project (such as ~/.claude or ~/.claude/hooks), is refused with a note (exit 0), and nothing is written."

…it' advice where init writes nothing

- git and Mercurial ignore only untracked files, so a .claude/CLAUDE.md the
  repository tracks is committed even when an ignore rule matches it (an
  unanchored CLAUDE.md in .gitignore). The ignored-root and kept-copy checks
  ask the repository (git ls-files --error-unmatch, sl/hg files) whether an
  ignored agent file is tracked; when that cannot be read, the copy is kept.
  doc-loads lists the new spawn.
- In the home folder or at the top of a settings folder in it, where init
  writes no agent docs: the setup reminder after each command stays quiet;
  upgrade with no block reports agentDocs.action error with the reason and
  what to do (move the project, or add the block by hand), not init; doctor's
  agent-docs fix says the same.
- The --agent-docs-path help uses the reviewer's wording; the changeset
  names the tracked-file rule and the three surfaces.
Tests: a tracked .claude/CLAUDE.md under an unanchored rule keeps its copy
(default and --agent claude), an untracked one is stripped, an unreadable
repository keeps it; the reminder in ~ and ~/.dotfiles; upgrade with no
block in ~/.dotfiles; doctor's fix there.

@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: the agent-docs layout, the project-root search and the home-folder refusal match architecture:cli-surface INV31, and the previous round's three fixes are in. One fix remains: when git ignores an untracked root CLAUDE.md only through .git/info/exclude or a global excludes file, init still strips the block from a committed .claude/CLAUDE.md, so a fresh clone gives Claude Code no copy where 0.7.1 kept one. Since the code already asks git whether the file is tracked, please also ask it whether the file is ignored (git check-ignore), widen the INV31 ignored-root sentence to match for maintainer approval, and pin the case in agent-docs.path-safety.test.mjs.

[Automated review]

* @returns {boolean}
*/
function uncommittedHere(targetDir, rel, unreadable) {
if (!ignoredHere(targetDir, rel, unreadable)) return false;

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 asks only the in-tree ignore reader, which never reads .git/info/exclude or core.excludesFile. With root CLAUDE.md untracked and ignored through either (git check-ignore CLAUDE.md exits 0), this returns false before trackedHere runs, so root CLAUDE.md counts as committed and the default strips the block from a tracked .claude/CLAUDE.md (or never adds one); a fresh clone then gives Claude Code no copy, where 0.7.1 kept it. Since trackedHere already runs git, asking git check-ignore -q -- <rel> for an untracked file here (with the sl/hg equivalents, or keeping the copy when they cannot answer) would close it, with a .git/info/exclude case in agent-docs.path-safety.test.mjs.

Conflicts, both sides kept: api/doctor/doctor.mjs, api/init/init.doc.mjs and init.type.mjs, assets/docs/working-with-ai.doc.mjs, clients/cli/commands/init.doc.mjs and setup-nudge.test.mjs, clients/cli/index.mjs, foundation/doc-compiler/doc-loads.test.mjs.
Global mode (main) treats a folder whose package.json declares no Astryx
package as outside a project: init prints no getting-started steps there and
the setup reminder stays quiet. Two #7497 fixtures moved to os.tmpdir() or
declare nothing, so they now declare @astryxdesign/core; --json output now
carries meta.answeredBy, which the remove-agents JSON check expects; and
main's outside-project init test now sees the GEMINI.md import #7497 always
writes.
…l excludes included

The ignored-root check read only the in-tree ignore files, never
.git/info/exclude or core.excludesFile, so with root CLAUDE.md untracked and
ignored through either, the default stripped (or never added) the block in a
tracked .claude/CLAUDE.md. Inside a repository, init now asks the repository
whether an agent file is untracked and ignored: `git check-ignore -q` (which
never reports a tracked file, and reads every ignore source), or
`sl`/`hg status -i -n`. When it cannot answer, the copy is kept. Outside a
repository the folder's ignore files answer, as before. This replaces the
separate tracked-file query and the ignoreFrom reader, which the repository's
answer covers, so file-protection.mjs is back to main's.
The INV31 ignored-root sentence and the changeset say so (the record line
stays with the others pending approval).
Tests: an untracked root CLAUDE.md ignored through .git/info/exclude, and
through core.excludesFile, beside a tracked .claude/CLAUDE.md keeps its copy;
the monorepo case runs in a real git repository.

@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: the agent-docs layout, the project-root search and the home-folder refusal match architecture:cli-surface INV31, and the previous round's .git/info/exclude fix is in, but CI's test-node now fails one of this pull request's own tests. "keeps the copy when the repository .hgignore cannot be parsed (fails closed)" in agent-docs.path-safety.test.mjs still expects the in-tree .hgignore reader this revision removes: Mercurial opens the bare .hg folder the test creates and answers that root CLAUDE.md is not ignored, so init strips the copy. Please build real Mercurial repositories in the three Mercurial cases (skipped when hg is missing or is Sapling, as the git cases skip without git) and make the fail-closed case a repository hg cannot open, such as a .hg/requires naming an unknown requirement.

[Automated review]

});
}

it('keeps the copy when the repository .hgignore cannot be parsed (fails closed)', () => {

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 case fails in CI's test-node on this head. The ignored-root check now asks hg status -i -n, and Mercurial opens the bare .hg folder created here, skips the invalid syntax: bogus line and answers that CLAUDE.md is not ignored, so init strips the block; the case passes only where hg cannot open the folder (Sapling's hg, or none installed). Suggest building real repositories with hg init for the three Mercurial cases, skipped when hg is missing or is Sapling as the git cases skip without git, and making this one a repository hg cannot open, such as a .hg/requires naming an unknown requirement.

…hg is installed

CI went red on GitHub's runners: their real Mercurial reads an .hgignore
with an unknown syntax line by skipping it, answers that root CLAUDE.md is
not ignored, and the copy moves, as the repository says. The test assumed
the box's hg would fail on that file. The code already treats a tool that
is missing, cannot start, times out, or exits with an undocumented code as
"cannot answer" and keeps the copy; its comment now says so.
The test now sets the search path itself: no hg, an hg that fails (255), and
one with an undocumented exit (2) keep the copy; an hg that answers with
nothing ignored moves it. The glob and regexp cases keep the same outcome
whether hg is installed or not.

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

Recommending approval: the agent-docs layout, the project-root search and the home-folder refusal match architecture:cli-surface INV31, and the Mercurial fail-closed test that failed CI on the previous revision now stubs hg and passes in test-node. Two things remain before merge: an engineering owner approves the INV31 and spec:AST-040 FR8 amendments on this head, and merging main clears the pr-a11y failure, which comes from a Token test that exists only on main.

[Automated review]

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 4a022fc

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 21, 2026
@josephfarina
josephfarina merged commit b74cf21 into main Oct 21, 2026
55 of 56 checks passed
@github-actions
github-actions Bot deleted the josephfarina/init-agent-docs-one-copy branch October 22, 2026 06:22

This branch was successfully deployed

1 active deployment
Preview — 4a022fc0 Deployed Oct 21, 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