@astryxdesign/cli 0.7.3-canary.b1e1936 → 0.7.3-canary.b74cf21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,10 +16,24 @@ export const doc = {
16
16
  summary: 'Initialize the design system in your project',
17
17
  description:
18
18
  'Non-interactive project setup (no prompts, so it behaves the same for humans, ' +
19
- 'agents, and CI). By default it installs the AGENTS.md/CLAUDE.md agent-docs, ' +
20
- 'including guidance from configured integrations, and prints getting-started ' +
21
- "steps. --features and --all print only the chosen features' guidance (no " +
22
- 'getting-started steps); the theme feature also writes an annotated theme template. ' +
19
+ 'agents, and CI). By default it writes the agent-docs block, including guidance ' +
20
+ 'from configured integrations, to AGENTS.md and to the Claude Code file the project ' +
21
+ 'has (CLAUDE.md, else .claude/CLAUDE.md; when CLAUDE.md exists, a block in ' +
22
+ '.claude/CLAUDE.md is removed, unless the project ignores CLAUDE.md, in which case a .claude/CLAUDE.md the ' +
23
+ 'project commits keeps a copy), and a one-line import of AGENTS.md to GEMINI.md ' +
24
+ 'unless GEMINI.md already imports it. It then prints getting-started steps. Agent ' +
25
+ 'docs go to the project root: the nearest folder at or above this one whose ' +
26
+ 'package.json declares an @astryxdesign package, else the nearest with any ' +
27
+ 'package.json, else this folder. The search stops at a repository root and never ' +
28
+ 'counts the home folder. In the home folder, or in a settings folder in it ' +
29
+ 'such as ~/.gemini outside a project, no agent docs are written. Every folder of the ' +
30
+ 'home folder whose name starts with a dot is a settings folder, and such a folder ' +
31
+ 'itself never counts as a project, even with a package.json; a project inside one, ' +
32
+ 'such as an agent worktree with its own package.json, works. The managed block is ' +
33
+ 'written whatever ignore rules or generated markers say; the text around it is never changed. ' +
34
+ '--features and --all print only ' +
35
+ "the chosen features' " +
36
+ 'guidance (no getting-started steps); the theme feature also writes an annotated theme template. ' +
23
37
  'Outside a project it writes the same files but prints no step that sets up a project: ' +
24
38
  'no getting-started steps, and no step that adds a theme to an app. ' +
25
39
  '--user writes the computer-level agent text instead (see the flag), in any folder, and touches nothing in the folder. ' +
@@ -44,8 +58,10 @@ export const doc = {
44
58
  flag: '--remove-agents',
45
59
  param: 'options.removeAgents',
46
60
  description:
47
- 'Remove the managed block from AGENTS.md, CLAUDE.md, .claude/CLAUDE.md, .cursorrules, .hermes.md and HERMES.md ' +
48
- "(deleting AGENTS.md or .claude/CLAUDE.md when only init's heading is left) and do nothing else. " +
61
+ 'Remove the managed block from AGENTS.md, CLAUDE.md, .claude/CLAUDE.md, GEMINI.md, .cursorrules, .hermes.md and HERMES.md, ' +
62
+ 'at the project root (where init writes them) and in this folder ' +
63
+ "(deleting AGENTS.md or .claude/CLAUDE.md when only init's heading is left, and GEMINI.md when nothing is left) and do nothing else. " +
64
+ 'Below the project root, a project-root agent file whose block resolves outside the project is left as it is, with a note. ' +
49
65
  '--features, --all, --agent and --agent-docs-path are refused; a file written with --agent-docs-path keeps its block',
50
66
  },
51
67
  {
@@ -66,7 +82,9 @@ export const doc = {
66
82
  choices: ['claude', 'cursor', 'codex', 'hermes', 'muse', 'all'],
67
83
  description:
68
84
  'Target AI tool for agent docs: claude (CLAUDE.md or .claude/CLAUDE.md, else creates .claude/CLAUDE.md), cursor (.cursorrules if present, else AGENTS.md), ' +
69
- 'codex and muse (AGENTS.md), hermes (.hermes.md or HERMES.md if present, else AGENTS.md), all (every existing agent doc, else AGENTS.md and .claude/CLAUDE.md). ' +
85
+ 'codex and muse (AGENTS.md), hermes (.hermes.md or HERMES.md if present, else AGENTS.md), all (every existing agent doc except GEMINI.md, which keeps its ' +
86
+ 'one-line import of AGENTS.md, else AGENTS.md and .claude/CLAUDE.md). With claude and all, when CLAUDE.md gets the block, .claude/CLAUDE.md gets none and ' +
87
+ 'a block already there is removed, unless the project ignores CLAUDE.md: then a .claude/CLAUDE.md the project commits gets a copy too, with claude and all alike. ' +
70
88
  'An unknown tool exits 1 with ERR_UNKNOWN_AGENT. ' +
71
89
  'Used only when agent docs are installed (the default, --all, or --features agents); --agent-docs-path takes precedence.',
72
90
  },
@@ -76,6 +94,7 @@ export const doc = {
76
94
  description:
77
95
  'Explicit file path(s) for agent docs, inside the project; takes precedence over --agent. ' +
78
96
  'If any path is outside the project, no agent docs are written and the command exits 1. ' +
97
+ '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. ' +
79
98
  'Used only when agent docs are installed',
80
99
  },
81
100
  ],
@@ -90,11 +109,11 @@ export const doc = {
90
109
  exitCodes: [
91
110
  {
92
111
  code: 0,
93
- when: 'success, including agent docs that could not be written for a reason other than a path escape (reported as docsError)',
112
+ 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 or a block-less import of an existing AGENTS.md; with --agent claude beside a CLAUDE.md, one whose block it would remove",
94
113
  },
95
114
  {
96
115
  code: 1,
97
- when: 'an unknown --agent (ERR_UNKNOWN_AGENT) or feature, an --agent-docs-path outside the project, --remove-agents combined with install options, --user combined with --features, --all, --agent or --agent-docs-path, or --all with --features (ERR_INVALID_ARGUMENT)',
116
+ when: 'an unknown --agent (ERR_UNKNOWN_AGENT) or feature, an --agent-docs-path outside the project, --remove-agents combined with install options, --user combined with --features, --all, --agent or --agent-docs-path, or --all with --features (ERR_INVALID_ARGUMENT); or, when init runs at the project root, an agent file 0.7.1 also wrote there that resolves outside the project (ERR_PATH_TRAVERSAL, docsError path-safety, nothing written)',
98
117
  },
99
118
  ],
100
119
  related: ['doctor', 'upgrade', 'build', 'theme'],
@@ -67,6 +67,7 @@ describe('astryx init flag interactions', () => {
67
67
  expect(help).toContain(file);
68
68
  }
69
69
  expect(help).toMatch(/--agent-docs-path are refused/);
70
+ expect(help).toMatch(/at the project root \(where init writes them\) and in this folder/);
70
71
 
71
72
  await initJson(['--agent-docs-path', 'docs/AI.md']);
72
73
  await initJson([]);
@@ -3,8 +3,8 @@
3
3
  /**
4
4
  * @file init command — thin wrapper around the init API.
5
5
  *
6
- * `astryx init` is non-interactive by default: it installs the AGENTS.md/
7
- * CLAUDE.md cheat sheet with NO prompts, so it behaves identically for humans,
6
+ * `astryx init` is non-interactive by default: it installs the agent-docs
7
+ * cheat sheet with NO prompts, so it behaves identically for humans,
8
8
  * AI agents, CI, and piped I/O — it never hangs or errors on a missing TTY.
9
9
  * Non-interactive feature install: `astryx init --features agents,theme,template`
10
10
  * Re-runnable: safe to run multiple times, idempotent.
@@ -541,7 +541,8 @@ describe('init outside a project (own)', () => {
541
541
  const dir = tmpDir('init');
542
542
  const json = await answer(['--json', 'init'], dir);
543
543
  expect(json.status).toBe(0);
544
- expect(json.written).toEqual(['AGENTS.md']);
544
+ // GEMINI.md gets its one-line import of AGENTS.md (spec cli-surface INV31).
545
+ expect(json.written).toEqual(['AGENTS.md', 'GEMINI.md']);
545
546
  expect(json.envelope.data.nextSteps).toBe(false);
546
547
  const text = await runCli(['init'], tmpDir('init-text'));
547
548
  expect(text.stdout).not.toContain('Next steps');
@@ -121,6 +121,25 @@ describe('enforcement layer 3 — per-command setup nudge', () => {
121
121
  expect(r.stderr).toMatch(NUDGE);
122
122
  });
123
123
 
124
+ it.each([
125
+ ['in the home folder', ''],
126
+ ['at the top of a settings folder in it', '.dotfiles'],
127
+ ])('stays quiet %s, where init writes no agent docs', async (_label, rel) => {
128
+ const saved = {HOME: process.env.HOME, USERPROFILE: process.env.USERPROFILE};
129
+ process.env.HOME = tmp;
130
+ process.env.USERPROFILE = tmp;
131
+ try {
132
+ write(path.join(rel, 'package.json'), '{"name":"t"}');
133
+ const r = await runCli(['docs', 'tokens'], path.join(tmp, rel));
134
+ expect(r.stderr).not.toMatch(NUDGE);
135
+ } finally {
136
+ for (const [key, value] of Object.entries(saved)) {
137
+ if (value === undefined) delete process.env[key];
138
+ else process.env[key] = value;
139
+ }
140
+ }
141
+ });
142
+
124
143
  it("in a project with only Core of another release, names adding the CLI at Core's version first, as the daily hint does", async () => {
125
144
  write(
126
145
  'package.json',
@@ -167,6 +186,48 @@ describe('enforcement layer 3 — per-command setup nudge', () => {
167
186
  expect((await runCli(['docs', 'tokens'], tmp)).stderr).not.toMatch(NUDGE);
168
187
  });
169
188
 
189
+ it('is quiet in a nested package once init has written the docs at the project root', async () => {
190
+ // init run in functions/ writes at the root that declares Astryx.
191
+ write('package.json', JSON.stringify({name: 'app', dependencies: {'@astryxdesign/core': '0.7.0'}}));
192
+ write('AGENTS.md', MARKER);
193
+ write('functions/package.json', '{"name":"functions"}');
194
+ const r = await runCli(['docs', 'tokens'], path.join(tmp, 'functions'));
195
+ expect(r.stderr).not.toMatch(NUDGE);
196
+ });
197
+
198
+ it('nudges in a nested package while the project root has no docs', async () => {
199
+ write('package.json', JSON.stringify({name: 'app', dependencies: {'@astryxdesign/core': '0.7.0'}}));
200
+ write('functions/package.json', '{"name":"functions"}');
201
+ const r = await runCli(['docs', 'tokens'], path.join(tmp, 'functions'));
202
+ expect(r.stderr).toMatch(NUDGE);
203
+ });
204
+
205
+ // Inside a git repository the project-root check above adds nothing to the
206
+ // walk up to the repository root: the same outcomes as without it.
207
+ it('inside a repository, is quiet in a nested package once init has written the docs at the project root', async () => {
208
+ fs.mkdirSync(path.join(tmp, '.git'));
209
+ write('package.json', JSON.stringify({name: 'app', dependencies: {'@astryxdesign/core': '0.7.0'}}));
210
+ write('AGENTS.md', MARKER);
211
+ write('functions/package.json', '{"name":"functions"}');
212
+ const r = await runCli(['docs', 'tokens'], path.join(tmp, 'functions'));
213
+ expect(r.stderr).not.toMatch(NUDGE);
214
+ });
215
+
216
+ it('inside a repository, still nudges when the only docs lie above the repository root', async () => {
217
+ write('package.json', JSON.stringify({name: 'outer', dependencies: {'@astryxdesign/core': '0.7.0'}}));
218
+ write('AGENTS.md', MARKER);
219
+ fs.mkdirSync(path.join(tmp, 'repo', '.git'), {recursive: true});
220
+ write('repo/package.json', '{"name":"repo"}');
221
+ // It declares Astryx: a folder that declares nothing is outside a
222
+ // project, where no reminder prints (spec AST-081 FR3).
223
+ write(
224
+ 'repo/functions/package.json',
225
+ JSON.stringify({name: 'functions', dependencies: {'@astryxdesign/core': '0.7.0'}}),
226
+ );
227
+ const r = await runCli(['docs', 'tokens'], path.join(tmp, 'repo', 'functions'));
228
+ expect(r.stderr).toMatch(NUDGE);
229
+ });
230
+
170
231
  it('does not nudge for the installer command itself', async () => {
171
232
  asProject();
172
233
  expect((await runCli(['init'], tmp)).stderr).not.toMatch(NUDGE);
@@ -32,7 +32,12 @@ import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
32
32
  import {installJsonShim} from './lib/json-shim.mjs';
33
33
  import {addDocHelp, markReportsResult} from './lib/define-command.mjs';
34
34
  import {doc as manifestDoc} from './commands/manifest.doc.mjs';
35
- import {isAstryxInitialized, isAstryxPromptInReach} from '../../foundation/agent-docs/agent-docs.mjs';
35
+ import {
36
+ agentDocsTargetDir,
37
+ assertAgentDocsTarget,
38
+ isAstryxInitialized,
39
+ isAstryxPromptInReach,
40
+ } from '../../foundation/agent-docs/agent-docs.mjs';
36
41
  import {CLI_ROOT} from '../../foundation/fs/paths.mjs';
37
42
  import {setupNudge} from '../../foundation/agent-docs/agent-doc-state.mjs';
38
43
  import * as debug from '../../foundation/debug/index.mjs';
@@ -635,6 +640,19 @@ export async function createProgram() {
635
640
  if (INTEGRATION_MANIFEST_FILES.some(file => fs.existsSync(path.join(cwd, file)))) return;
636
641
  if (inOwnSourceCheckout(cwd)) return; // developing Astryx itself, not an app
637
642
  if (isAstryxPromptInReach(cwd)) return; // already set up — stay quiet
643
+ // Where init writes the docs, by init's own rule: the project root, which
644
+ // can sit above a nested package such as functions/. Inside a git
645
+ // repository the walk above already reaches it (the root never lies
646
+ // above the repository root), so this changes nothing there; outside a
647
+ // repository the walk checks only cwd, and this finds the root.
648
+ if (isAstryxInitialized(agentDocsTargetDir(cwd))) return;
649
+ // In the home folder, or at the top of a settings folder in it, init
650
+ // writes no agent docs, so naming it would repeat on every command.
651
+ try {
652
+ assertAgentDocsTarget(agentDocsTargetDir(cwd));
653
+ } catch {
654
+ return;
655
+ }
638
656
  // Same wording as the core/cli postinstall nudges. getCliInvocation()
639
657
  // renders the correct form for THIS project — an integration's cliCommand,
640
658
  // scoped `npx @astryxdesign/cli` one-off, or `<pm> astryx` when installed —
@@ -4,15 +4,25 @@
4
4
  /**
5
5
  * Find all existing agent doc files in a directory, across EVERY location any
6
6
  * preset can write (see {@link AGENT_DOC_PATHS}: AGENTS.md, CLAUDE.md,
7
- * .claude/CLAUDE.md, .cursorrules, .hermes.md, HERMES.md).
7
+ * .claude/CLAUDE.md, GEMINI.md, .cursorrules, .hermes.md, HERMES.md).
8
8
  * @param {string} targetDir
9
9
  * @returns {string[]} Relative paths of existing agent doc files
10
10
  */
11
11
  export function discoverAgentDocs(targetDir: string): string[];
12
+ /**
13
+ * Whether `content` holds an Astryx block. A managed block that only imports
14
+ * another file (the one-line `@./AGENTS.md` that init writes to GEMINI.md) does
15
+ * not count: it holds nothing once that file has lost its block. A malformed
16
+ * block still counts, so a half-written file reads as set up.
17
+ *
18
+ * @param {string} content
19
+ * @returns {boolean}
20
+ */
21
+ export function holdsAstryxBlock(content: string): boolean;
12
22
  /**
13
23
  * Single source of truth for "is Astryx set up in this project?" — true when any
14
- * agent-doc file already carries the Astryx marker, i.e. `init` / `agent-docs`
15
- * has run. Reused by the init & upgrade commands, the per-command setup nudge
24
+ * agent-doc file already holds an Astryx block, i.e. `init` / `agent-docs` has
25
+ * run. Reused by the init & upgrade commands, the per-command setup nudge
16
26
  * (enforcement layer 3), and the cli postinstall nudge (layer 2). Core's
17
27
  * postinstall (separate package, layer 1) mirrors the same marker contract.
18
28
  *
@@ -68,6 +78,7 @@ export function shouldNudge({ scriptPath, npmCommand, isSetUp }?: {
68
78
  export const AGENTS_MD: "AGENTS.md";
69
79
  export const CLAUDE_MD: "CLAUDE.md";
70
80
  export const CLAUDE_DIR_MD: ".claude/CLAUDE.md";
81
+ export const GEMINI_MD: "GEMINI.md";
71
82
  export const CURSOR_RULES: ".cursorrules";
72
83
  export const HERMES_DOT_MD: ".hermes.md";
73
84
  export const HERMES_MD: "HERMES.md";
@@ -77,10 +88,12 @@ export const LEGACY_MARKER_START: "<!-- XDS:START -->";
77
88
  export const LEGACY_MARKER_END: "<!-- XDS:END -->";
78
89
  /**
79
90
  * The canonical set of EVERY location an --agent preset (or the default) can
80
- * write the Astryx block. SINGLE SOURCE OF TRUTH: discovery, removal, and the
81
- * `isAstryxInitialized` predicate all derive from this list, so "where init
82
- * writes" and "where we look" can never drift. (Explicit --agent-docs-path
83
- * targets are user-chosen and not enumerable here.)
91
+ * write a managed Astryx block — the full block, or the one-line import of
92
+ * AGENTS.md that the default writes to GEMINI.md. SINGLE
93
+ * SOURCE OF TRUTH: discovery, removal, and the `isAstryxInitialized` predicate
94
+ * all derive from this list, so "where init writes" and "where we look" can
95
+ * never drift. (Explicit --agent-docs-path targets are user-chosen and not
96
+ * enumerable here.)
84
97
  */
85
98
  export const AGENT_DOC_PATHS: string[];
86
99
  /**
@@ -29,6 +29,7 @@ import * as path from 'node:path';
29
29
  export const AGENTS_MD = 'AGENTS.md';
30
30
  export const CLAUDE_MD = 'CLAUDE.md';
31
31
  export const CLAUDE_DIR_MD = '.claude/CLAUDE.md'; // cross-platform literal
32
+ export const GEMINI_MD = 'GEMINI.md';
32
33
  export const CURSOR_RULES = '.cursorrules';
33
34
  export const HERMES_DOT_MD = '.hermes.md';
34
35
  export const HERMES_MD = 'HERMES.md';
@@ -41,15 +42,18 @@ export const LEGACY_MARKER_END = '<!-- XDS:END -->';
41
42
 
42
43
  /**
43
44
  * The canonical set of EVERY location an --agent preset (or the default) can
44
- * write the Astryx block. SINGLE SOURCE OF TRUTH: discovery, removal, and the
45
- * `isAstryxInitialized` predicate all derive from this list, so "where init
46
- * writes" and "where we look" can never drift. (Explicit --agent-docs-path
47
- * targets are user-chosen and not enumerable here.)
45
+ * write a managed Astryx block — the full block, or the one-line import of
46
+ * AGENTS.md that the default writes to GEMINI.md. SINGLE
47
+ * SOURCE OF TRUTH: discovery, removal, and the `isAstryxInitialized` predicate
48
+ * all derive from this list, so "where init writes" and "where we look" can
49
+ * never drift. (Explicit --agent-docs-path targets are user-chosen and not
50
+ * enumerable here.)
48
51
  */
49
52
  export const AGENT_DOC_PATHS = [
50
53
  AGENTS_MD, // Codex / ChatGPT / Muse / generic
51
54
  CLAUDE_MD, // Claude Code (root)
52
55
  CLAUDE_DIR_MD, // Claude Code (.claude/CLAUDE.md)
56
+ GEMINI_MD, // Gemini CLI
53
57
  CURSOR_RULES, // Cursor
54
58
  HERMES_DOT_MD, // Hermes
55
59
  HERMES_MD, // Hermes
@@ -64,7 +68,7 @@ export const INIT_MARKERS = [MARKER_START, LEGACY_MARKER_START];
64
68
  /**
65
69
  * Find all existing agent doc files in a directory, across EVERY location any
66
70
  * preset can write (see {@link AGENT_DOC_PATHS}: AGENTS.md, CLAUDE.md,
67
- * .claude/CLAUDE.md, .cursorrules, .hermes.md, HERMES.md).
71
+ * .claude/CLAUDE.md, GEMINI.md, .cursorrules, .hermes.md, HERMES.md).
68
72
  * @param {string} targetDir
69
73
  * @returns {string[]} Relative paths of existing agent doc files
70
74
  */
@@ -72,10 +76,33 @@ export function discoverAgentDocs(targetDir) {
72
76
  return AGENT_DOC_PATHS.filter(p => fs.existsSync(path.join(targetDir, p)));
73
77
  }
74
78
 
79
+ /**
80
+ * Whether `content` holds an Astryx block. A managed block that only imports
81
+ * another file (the one-line `@./AGENTS.md` that init writes to GEMINI.md) does
82
+ * not count: it holds nothing once that file has lost its block. A malformed
83
+ * block still counts, so a half-written file reads as set up.
84
+ *
85
+ * @param {string} content
86
+ * @returns {boolean}
87
+ */
88
+ export function holdsAstryxBlock(content) {
89
+ for (const marker of INIT_MARKERS) {
90
+ let at = content.indexOf(marker);
91
+ while (at !== -1) {
92
+ const from = at + marker.length;
93
+ const end = content.indexOf('<!--', from);
94
+ const inner = (end === -1 ? content.slice(from) : content.slice(from, end)).trim();
95
+ if (!/^@\S+$/.test(inner)) return true;
96
+ at = content.indexOf(marker, from);
97
+ }
98
+ }
99
+ return false;
100
+ }
101
+
75
102
  /**
76
103
  * Single source of truth for "is Astryx set up in this project?" — true when any
77
- * agent-doc file already carries the Astryx marker, i.e. `init` / `agent-docs`
78
- * has run. Reused by the init & upgrade commands, the per-command setup nudge
104
+ * agent-doc file already holds an Astryx block, i.e. `init` / `agent-docs` has
105
+ * run. Reused by the init & upgrade commands, the per-command setup nudge
79
106
  * (enforcement layer 3), and the cli postinstall nudge (layer 2). Core's
80
107
  * postinstall (separate package, layer 1) mirrors the same marker contract.
81
108
  *
@@ -86,7 +113,7 @@ export function isAstryxInitialized(targetDir = process.cwd()) {
86
113
  for (const rel of discoverAgentDocs(targetDir)) {
87
114
  try {
88
115
  const content = fs.readFileSync(path.join(targetDir, rel), 'utf-8');
89
- if (INIT_MARKERS.some(m => content.includes(m))) {
116
+ if (holdsAstryxBlock(content)) {
90
117
  return true;
91
118
  }
92
119
  } catch {
@@ -1,6 +1,31 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Throw {@link AgentDocsHomeError} when `targetDir` is the home folder, or a
6
+ * settings folder in it outside a project.
7
+ * @param {string} targetDir
8
+ */
9
+ export function assertAgentDocsTarget(targetDir: string): void;
10
+ /**
11
+ * The folder a run started in `cwd` writes agent docs to: the nearest folder at
12
+ * or above it whose package.json declares an `@astryxdesign` package, else the
13
+ * nearest folder with any package.json. The search stops at a repository root
14
+ * and never reaches the home folder, so a stray `~/package.json` cannot pull
15
+ * the docs there.
16
+ * @param {string} cwd
17
+ * @returns {string | null} null when no folder it searches has a package.json;
18
+ * init then writes where it runs, as before.
19
+ */
20
+ export function resolveAgentDocsRoot(cwd: string): string | null;
21
+ /**
22
+ * The folder `init` run in `cwd` writes the agent docs to: the project root
23
+ * {@link resolveAgentDocsRoot} finds, else `cwd` itself. The one definition
24
+ * that init, its removal, and the per-command setup nudge all use.
25
+ * @param {string} cwd
26
+ * @returns {string}
27
+ */
28
+ export function agentDocsTargetDir(cwd: string): string;
4
29
  /**
5
30
  * Parse the Astryx version a managed block was generated for, from its header
6
31
  * line ("Astryx v1.2.3 · N components"). Returns null when the block predates
@@ -23,6 +48,8 @@ export function parseBlockVersion(content: string): string | null;
23
48
  * - `current` — every managed block already matches the installed version.
24
49
  * And the project is `missing` when no managed block exists anywhere (the repo
25
50
  * has agent-doc files without our markers, or none at all — i.e. never `init`ed).
51
+ * A managed import of AGENTS.md is not a block here: it names no version and
52
+ * stays current while AGENTS.md holds the block.
26
53
  *
27
54
  * @param {string} targetDir
28
55
  * @param {string} [installedVersion] Defaults to the installed core version.
@@ -170,34 +197,70 @@ export function injectAgentsMd(targetDir: string, version: string): void;
170
197
  */
171
198
  export function injectClaudeMd(targetDir: string, version: string): boolean;
172
199
  /**
173
- * Remove Astryx section from a file.
174
- * If the file becomes empty (only boilerplate header remains), deletes it.
200
+ * Remove the Astryx-managed block, between its markers, from a file, leaving
201
+ * every other line as it is. With `deleteIfEmpty`, the file is deleted when
202
+ * nothing is left but whitespace or the exact heading init writes into a file
203
+ * it creates; with `deleteIfBlank`, only when nothing but whitespace is left.
175
204
  *
176
205
  * @param {string} filePath
177
- * @param {{deleteIfEmpty?: boolean}} [options]
206
+ * @param {{deleteIfEmpty?: boolean, deleteIfBlank?: boolean}} [options]
178
207
  * @returns {boolean} Whether the Astryx section was found and removed
179
208
  */
180
- export function removeXdsBlock(filePath: string, { deleteIfEmpty }?: {
209
+ export function removeXdsBlock(filePath: string, { deleteIfEmpty, deleteIfBlank }?: {
181
210
  deleteIfEmpty?: boolean;
211
+ deleteIfBlank?: boolean;
182
212
  }): boolean;
183
213
  /**
184
214
  * Remove Astryx section from all known agent doc files.
185
215
  * @param {string} targetDir
216
+ * @param {object} [options]
217
+ * @param {string} [options.shownFrom] - Folder the logged paths are shown
218
+ * relative to; defaults to `targetDir`.
219
+ * @param {Set<string>} [options.skip] - Files left as they are.
186
220
  * @returns {string[]} the project-relative files a block was removed from.
187
221
  * @throws {PathSafetyError} `ERR_PATH_TRAVERSAL` when a file it would change
188
222
  * resolves outside `targetDir`; nothing is changed.
189
223
  */
190
- export function removeAgentDocs(targetDir: string): string[];
224
+ export function removeAgentDocs(targetDir: string, { shownFrom, skip }?: {
225
+ shownFrom?: string | undefined;
226
+ skip?: Set<string> | undefined;
227
+ }): string[];
228
+ /**
229
+ * Remove the managed block where init writes it, the project root (see
230
+ * {@link resolveAgentDocsRoot}), and in `cwd`, so a block an earlier version
231
+ * wrote in that folder goes too. Each folder is checked before anything is
232
+ * changed. Run below the project root, a project-root agent file holding a
233
+ * block that resolves outside the project is left as it is and reported to
234
+ * `onSkipped`, as install does there; 0.7.x touched only `cwd`. A file in
235
+ * `cwd`, or at the root when run there, that resolves outside refuses the run.
236
+ *
237
+ * @param {string} cwd
238
+ * @param {{onSkipped?: (rel: string, reason: string) => void}} [options]
239
+ * @returns {string[]} the files a block was removed from, relative to `cwd`
240
+ * @throws {PathSafetyError} `ERR_PATH_TRAVERSAL`; nothing is changed
241
+ */
242
+ export function removeProjectAgentDocs(cwd: string, { onSkipped }?: {
243
+ onSkipped?: (rel: string, reason: string) => void;
244
+ }): string[];
191
245
  /**
192
246
  * Programmatic entry point for installing agent docs.
193
247
  * Used by the init command, upgrade command, and agent-docs command.
194
248
  *
195
- * Strategy (when no agent/paths specified):
196
- * - Discover all existing agent doc files.
197
- * - Leave `@path` import wrappers untouched; if an older run expanded a block
198
- * into one, remove that duplicate block.
199
- * - Initialize or refresh every standalone file.
200
- * - If nothing exists, create AGENTS.md as the tool-agnostic default.
249
+ * Default strategy (no agent/paths specified), so every agent reads the block:
250
+ * - Write the block to AGENTS.md (created when missing).
251
+ * - Write the block to the project's Claude Code file: root CLAUDE.md when it
252
+ * exists, else an existing .claude/CLAUDE.md, even when it imports AGENTS.md.
253
+ * Remove a block from the other one. Create no Claude file.
254
+ * - Write a managed import of AGENTS.md to GEMINI.md (created when missing),
255
+ * unless GEMINI.md already imports AGENTS.md.
256
+ * - Keep a full block in every other existing standalone file.
257
+ * - Leave every other `@path` import wrapper untouched; if an older run
258
+ * expanded a block into one, remove that duplicate block. When a wrapper
259
+ * imports a file other than AGENTS.md, the project keeps its own layout:
260
+ * every standalone file gets the block.
261
+ * A refresh (`onlyReplace`) rewrites existing blocks in place, the Claude
262
+ * file's copy included, leaves imports of AGENTS.md as they are, and creates
263
+ * nothing.
201
264
  *
202
265
  * @param {string} targetDir
203
266
  * @param {object} [options]
@@ -211,11 +274,21 @@ export function removeAgentDocs(targetDir: string): string[];
211
274
  * so an integration's topics reach the agent.
212
275
  * @param {string} [options.renderedBlock] - Fully rendered expected block. Init
213
276
  * and upgrade pass one shared block to every target.
277
+ * @param {(rel: string, reason: string) => void} [options.onSkipped] - Called
278
+ * for each file skipped because it resolves outside `targetDir` and 0.7.1
279
+ * never wrote it: GEMINI.md, or any file when `refuseEscapes` is false.
280
+ * @param {boolean} [options.refuseEscapes] - Whether a file 0.7.1 wrote that
281
+ * resolves outside `targetDir` refuses the run (default). Init passes false
282
+ * when it runs below the project root, where 0.7.1 wrote in the folder it
283
+ * ran in instead.
214
284
  * @returns {string[]} List of files written
215
285
  * @throws {import('../fs/path-safety.mjs').PathSafetyError} when a file it would
216
286
  * write resolves outside `targetDir`; nothing is written.
287
+ * @throws {AgentDocsHomeError} when `targetDir` is the home folder, or a settings
288
+ * folder in it outside a project, or, with `paths`, when a file's own folder
289
+ * is; nothing is written.
217
290
  */
218
- export function installAgentDocs(targetDir: string, { zh, lang, agent, paths, onlyReplace, topics, renderedBlock, }?: {
291
+ export function installAgentDocs(targetDir: string, { zh, lang, agent, paths, onlyReplace, topics, renderedBlock, onSkipped, refuseEscapes, }?: {
219
292
  zh?: boolean | undefined;
220
293
  lang?: string | undefined;
221
294
  agent?: string | undefined;
@@ -223,7 +296,22 @@ export function installAgentDocs(targetDir: string, { zh, lang, agent, paths, on
223
296
  onlyReplace?: boolean | undefined;
224
297
  topics?: string[] | undefined;
225
298
  renderedBlock?: string | undefined;
299
+ onSkipped?: ((rel: string, reason: string) => void) | undefined;
300
+ refuseEscapes?: boolean | undefined;
226
301
  }): string[];
302
+ /**
303
+ * Thrown when agent docs would be written into the home folder, or into a
304
+ * settings folder in it such as `~/.gemini` outside a project. Agents read the
305
+ * files there (for example `~/.claude/CLAUDE.md` or `~/.gemini/GEMINI.md`) in
306
+ * every project, so a project's version-pinned block never goes there. Removal
307
+ * stays allowed.
308
+ */
309
+ export class AgentDocsHomeError extends Error {
310
+ /** @param {string} dir */
311
+ constructor(dir: string);
312
+ /** The refused folder. */
313
+ dir: string;
314
+ }
227
315
  import { discoverAgentDocs } from './agent-doc-state.mjs';
228
316
  import { isAstryxInitialized } from './agent-doc-state.mjs';
229
317
  import { isAstryxPromptInReach } from './agent-doc-state.mjs';