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

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.
Files changed (234) hide show
  1. package/README.md +68 -68
  2. package/api/build/blocks/blocks.d.mts +6 -4
  3. package/api/build/blocks/blocks.mjs +103 -20
  4. package/api/build/blocks/blocks.test.mjs +126 -13
  5. package/api/build/blocks/blocks.weights.json +1 -1
  6. package/api/build/kit/answer.d.mts +5 -4
  7. package/api/build/kit/answer.mjs +114 -12
  8. package/api/build/kit/answer.test.mjs +73 -3
  9. package/api/build/kit/signals.d.mts +8 -0
  10. package/api/build/kit/signals.mjs +10 -0
  11. package/api/build/tree.test.mjs +19 -11
  12. package/api/component/component-replacement.test.mjs +1 -0
  13. package/api/component/component.mjs +17 -3
  14. package/api/component/component.test.mjs +15 -0
  15. package/api/component/doc-links.test.mjs +2 -2
  16. package/api/docs/_adapter.d.mts +2 -2
  17. package/api/docs/_adapter.mjs +61 -18
  18. package/api/docs/docs-homes.test.mjs +127 -0
  19. package/api/docs/docs.doc.mjs +3 -3
  20. package/api/docs/docs.test.mjs +28 -18
  21. package/api/docs/integration-tree.test.mjs +20 -20
  22. package/api/docs/integrationDocs.test.mjs +1 -1
  23. package/api/docs/namespace-section.test.mjs +6 -6
  24. package/api/docs/reference-blocks.test.mjs +2 -2
  25. package/api/doctor/doctor.mjs +102 -24
  26. package/api/doctor/doctor.test.mjs +37 -12
  27. package/api/hook/hook.mjs +1 -1
  28. package/api/init/init.doc.mjs +20 -6
  29. package/api/init/init.test.mjs +18 -2
  30. package/api/init/init.type.d.mts +3 -3
  31. package/api/init/init.type.mjs +3 -3
  32. package/api/init/remove/remove.mjs +17 -4
  33. package/api/init/remove/remove.test.mjs +114 -2
  34. package/api/init/run/run.mjs +69 -6
  35. package/api/integration/_adapter.d.mts +8 -0
  36. package/api/integration/_adapter.mjs +21 -1
  37. package/api/integration/authoring-checks.test.mjs +220 -0
  38. package/api/integration/pack-check.mjs +110 -4
  39. package/api/integration/pack-check.test.mjs +69 -0
  40. package/api/integration/validate-integration-fixes.test.mjs +6 -5
  41. package/api/integration/validate-integration-gaps.test.mjs +304 -1
  42. package/api/integration/validate-integration.d.mts +6 -1
  43. package/api/integration/validate-integration.mjs +82 -13
  44. package/api/integration/validate-integration.type.d.mts +37 -4
  45. package/api/integration/validate-integration.type.mjs +28 -5
  46. package/api/integration/validateIntegration.doc.mjs +1 -1
  47. package/api/search/_adapter.d.mts +16 -0
  48. package/api/search/_adapter.mjs +39 -0
  49. package/api/search/_adapter.test.mjs +173 -0
  50. package/api/search/_candidate-score.mjs +1 -1
  51. package/api/search/_entries.d.mts +11 -0
  52. package/api/search/_entries.mjs +77 -3
  53. package/api/search/_entries.test.mjs +48 -0
  54. package/api/search/_gather-docs.mjs +3 -3
  55. package/api/search/search.doc.mjs +1 -1
  56. package/api/search/search.mjs +6 -2
  57. package/api/search/search.test.mjs +14 -14
  58. package/api/theme/build/build.packed-old-core.test.mjs +1 -0
  59. package/api/upgrade/_adapter.d.mts +57 -9
  60. package/api/upgrade/_adapter.mjs +198 -28
  61. package/api/upgrade/registry/registry.d.mts +10 -4
  62. package/api/upgrade/registry/registry.mjs +33 -16
  63. package/api/upgrade/registry/registry.test.mjs +85 -0
  64. package/api/upgrade/run/run.d.mts +4 -2
  65. package/api/upgrade/run/run.mjs +13 -2
  66. package/api/upgrade/run/run.test.mjs +417 -3
  67. package/api/upgrade/upgrade.doc.mjs +10 -5
  68. package/api/upgrade/upgrade.mjs +13 -2
  69. package/api/upgrade/upgrade.test.mjs +194 -0
  70. package/api/upgrade/upgrade.type.d.mts +5 -3
  71. package/api/upgrade/upgrade.type.mjs +8 -6
  72. package/assets/docs/author-a-theme.doc.mjs +2 -2
  73. package/assets/docs/is-my-code-good.doc.mjs +287 -0
  74. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  75. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  76. package/assets/docs/tree/add-a-topic.doc.mjs +2 -2
  77. package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
  78. package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
  79. package/assets/docs/tree/block-template.doc.mjs +1 -1
  80. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  81. package/assets/docs/tree/building-blocks.doc.mjs +2 -2
  82. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  83. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  84. package/assets/docs/tree/checks.doc.mjs +3 -3
  85. package/assets/docs/tree/cli-command.doc.mjs +1 -1
  86. package/assets/docs/tree/cli.doc.mjs +1 -1
  87. package/assets/docs/tree/codemods.doc.mjs +1 -1
  88. package/assets/docs/tree/component-family.doc.mjs +1 -1
  89. package/assets/docs/tree/component-imports.doc.mjs +1 -1
  90. package/assets/docs/tree/components.doc.mjs +1 -1
  91. package/assets/docs/tree/configuration.doc.mjs +1 -1
  92. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  93. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  94. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  95. package/assets/docs/tree/docs.doc.mjs +1 -1
  96. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  97. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  98. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  99. package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
  100. package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
  101. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  102. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  103. package/assets/docs/tree/global-integrations.doc.mjs +2 -2
  104. package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
  105. package/assets/docs/tree/help.doc.mjs +2 -2
  106. package/assets/docs/tree/links.doc.mjs +1 -1
  107. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  108. package/assets/docs/tree/page-template.doc.mjs +1 -1
  109. package/assets/docs/tree/publishing.doc.mjs +1 -1
  110. package/assets/docs/tree/quick-start.doc.mjs +1 -1
  111. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  112. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  113. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  114. package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
  115. package/assets/docs/tree/ship.doc.mjs +2 -2
  116. package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
  117. package/assets/docs/tree/single-component.doc.mjs +1 -1
  118. package/assets/docs/tree/start-a-template.doc.mjs +1 -1
  119. package/assets/docs/tree/subcomponent.doc.mjs +1 -1
  120. package/assets/docs/tree/template-assets.doc.mjs +1 -1
  121. package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
  122. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  123. package/assets/docs/tree/template-grading-rubric.doc.mjs +17 -38
  124. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  125. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  126. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  127. package/assets/docs/tree/templates.doc.mjs +1 -1
  128. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  129. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  130. package/assets/docs/tree/themes.doc.mjs +1 -1
  131. package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
  132. package/assets/docs/tree/upgrading.doc.mjs +1 -1
  133. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  134. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  135. package/assets/docs/tree/versioning.doc.mjs +5 -1
  136. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  137. package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
  138. package/assets/docs/use-integrations.doc.mjs +120 -0
  139. package/assets/docs/working-with-ai.doc.mjs +6 -2
  140. package/assets/templates/themes/butter/butterTheme.ts +4 -2
  141. package/assets/templates/themes/stone/stoneTheme.ts +4 -2
  142. package/assets/templates/themes/y2k/y2kTheme.ts +4 -2
  143. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  144. package/authoring/integration/integration.doc.mjs +1 -1
  145. package/authoring/integration/type.ts +1 -1
  146. package/clients/cli/command-result-coverage.test.mjs +6 -5
  147. package/clients/cli/commands/build-theme.color-scheme.test.mjs +1 -1
  148. package/clients/cli/commands/{component/index.mjs → component.mjs} +37 -37
  149. package/clients/cli/commands/component.test.mjs +6 -6
  150. package/clients/cli/commands/docs.doc.mjs +2 -2
  151. package/clients/cli/commands/docs.mjs +1 -1
  152. package/clients/cli/commands/docs.test.mjs +14 -14
  153. package/clients/cli/commands/doctor-integration.test.mjs +49 -1
  154. package/clients/cli/commands/doctor.mjs +10 -0
  155. package/clients/cli/commands/doctor.test.mjs +65 -0
  156. package/clients/cli/commands/{hook/index.mjs → hook.mjs} +22 -22
  157. package/clients/cli/commands/import-hint-correctness.test.mjs +1 -1
  158. package/clients/cli/commands/init.behavior.test.mjs +230 -1
  159. package/clients/cli/commands/init.doc.mjs +28 -9
  160. package/clients/cli/commands/init.flag-help.test.mjs +1 -0
  161. package/clients/cli/commands/init.mjs +2 -2
  162. package/clients/cli/commands/integration-check.test.mjs +48 -0
  163. package/clients/cli/commands/integration.doc.mjs +1 -1
  164. package/clients/cli/commands/manifest.doc.mjs +1 -1
  165. package/clients/cli/commands/manifest.mjs +67 -0
  166. package/clients/cli/commands/outside-project.test.mjs +2 -1
  167. package/clients/cli/commands/postinstall.doc.mjs +23 -0
  168. package/clients/cli/commands/postinstall.mjs +31 -0
  169. package/clients/cli/commands/setup-nudge.test.mjs +61 -0
  170. package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
  171. package/clients/cli/commands/upgrade.doc.mjs +4 -2
  172. package/clients/cli/commands/upgrade.mjs +9 -2
  173. package/clients/cli/commands/upgrade.subfolder-path.test.mjs +97 -0
  174. package/clients/cli/index.mjs +29 -86
  175. package/clients/cli/lib/component-format.mjs +1 -1
  176. package/clients/cli/lib/define-command.mjs +12 -7
  177. package/clients/cli/lib/exit-codes.test.mjs +5 -0
  178. package/clients/cli/lib/manifest.test.mjs +12 -0
  179. package/clients/cli/lib/welcome-box.mjs +50 -0
  180. package/foundation/agent-docs/agent-doc-state.d.mts +20 -7
  181. package/foundation/agent-docs/agent-doc-state.mjs +35 -8
  182. package/foundation/agent-docs/agent-docs.d.mts +100 -12
  183. package/foundation/agent-docs/agent-docs.mjs +1012 -100
  184. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +1239 -17
  185. package/foundation/agent-docs/agent-docs.test.mjs +683 -39
  186. package/foundation/config/project.mjs +5 -20
  187. package/foundation/config/project.test.mjs +56 -0
  188. package/foundation/discovery/authoring-self-docs.d.mts +7 -0
  189. package/foundation/discovery/authoring-self-docs.mjs +16 -4
  190. package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
  191. package/foundation/discovery/authoring-surface.d.mts +1 -1
  192. package/foundation/discovery/authoring-surface.mjs +2 -2
  193. package/foundation/discovery/authoring-surface.test.mjs +1 -1
  194. package/foundation/discovery/cli-self-docs.d.mts +2 -1
  195. package/foundation/discovery/cli-self-docs.mjs +4 -3
  196. package/foundation/discovery/cli-self-docs.test.mjs +2 -2
  197. package/foundation/discovery/runner-allowlist.d.mts +2 -4
  198. package/foundation/discovery/runner-allowlist.mjs +2 -4
  199. package/foundation/discovery/runner-commands.d.mts +77 -0
  200. package/foundation/discovery/runner-commands.mjs +294 -0
  201. package/foundation/discovery/runner-commands.test.mjs +128 -0
  202. package/foundation/discovery/stray-pointers.test.mjs +1 -1
  203. package/foundation/discovery/template-adapter.mjs +18 -1
  204. package/foundation/discovery/template-needs.mjs +1 -44
  205. package/foundation/discovery/theme-discovery.mjs +147 -3
  206. package/foundation/doc-compiler/doc-loads.test.mjs +29 -9
  207. package/foundation/doc-compiler/read.mjs +59 -1
  208. package/foundation/doc-compiler/read.test.mjs +11 -2
  209. package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
  210. package/foundation/doc-compiler/tree.d.mts +32 -6
  211. package/foundation/doc-compiler/tree.mjs +77 -43
  212. package/foundation/doc-compiler/tree.test.mjs +7 -7
  213. package/foundation/fs/paths.d.mts +70 -8
  214. package/foundation/fs/paths.mjs +526 -35
  215. package/foundation/fs/paths.test.mjs +430 -54
  216. package/foundation/fs/read-record.d.mts +18 -0
  217. package/foundation/fs/read-record.mjs +131 -0
  218. package/foundation/fs/read-record.test.mjs +77 -0
  219. package/foundation/integrations/autolink.d.mts +2 -1
  220. package/foundation/integrations/autolink.mjs +4 -13
  221. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  222. package/foundation/integrations/cli-peer-version.mjs +132 -0
  223. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  224. package/foundation/integrations/exports-subpaths.d.mts +57 -0
  225. package/foundation/integrations/exports-subpaths.mjs +113 -0
  226. package/foundation/integrations/integrations.d.mts +20 -1
  227. package/foundation/integrations/integrations.mjs +59 -2
  228. package/foundation/integrations/public-imports.d.mts +118 -0
  229. package/foundation/integrations/public-imports.mjs +1769 -0
  230. package/foundation/integrations/public-imports.test.mjs +1793 -0
  231. package/foundation/integrations/validate-contributions.d.mts +19 -0
  232. package/foundation/integrations/validate-contributions.mjs +172 -3
  233. package/foundation/response/response-types.doc.mjs +1 -1
  234. package/package.json +9 -9
@@ -1,12 +1,124 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
  import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
3
- import * as fs from 'node:fs'; import * as path from 'node:path';
3
+ import * as fs from 'node:fs'; import * as path from 'node:path'; import * as os from 'node:os';
4
4
  import {init} from '../init.mjs'; import {remove} from './remove.mjs'; import {logger} from '../../logger.mjs';
5
5
  let dir;
6
- beforeEach(() => { dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-rm-')); fs.writeFileSync(path.join(dir,'package.json'),JSON.stringify({name:'c',version:'1.0.0'})); });
6
+ beforeEach(() => { dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-rm-')); fs.writeFileSync(path.join(dir,'package.json'),JSON.stringify({name:'c',version:'1.0.0'})); });
7
7
  afterEach(() => { fs.rmSync(dir,{recursive:true,force:true}); logger.setSilent(true); });
8
8
  describe('init.remove says whether anything was removed', () => {
9
9
  it('false on clean', async () => { const r=await remove({cwd:dir}); expect(r.type).toBe('init.remove'); expect(r.data.removed).toBe(false); });
10
10
  it('true then false', async () => { await init({features:['agents']},{cwd:dir}); expect(fs.readFileSync(path.join(dir,'AGENTS.md'),'utf8')).toContain('<!-- ASTRYX:START -->'); const a=await remove({cwd:dir}); expect(a.data.removed).toBe(true); const b=await remove({cwd:dir}); expect(b.data.removed).toBe(false); });
11
11
  it('human line', async () => { const l=[]; const s=vi.spyOn(console,'log').mockImplementation((...a)=>l.push(a.join(' '))); logger.setSilent(false); try{await remove({cwd:dir});}finally{logger.setSilent(true);s.mockRestore();} expect(l.join('\n')).toContain('Nothing to remove'); });
12
12
  });
13
+
14
+ describe('init.remove acts where init writes, the project root, and in the folder it runs in', () => {
15
+ /** @type {string} */
16
+ let project;
17
+ beforeEach(() => {
18
+ project = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-rm-root-'));
19
+ fs.writeFileSync(
20
+ path.join(project, 'package.json'),
21
+ JSON.stringify({name: 'app', dependencies: {'@astryxdesign/core': '1.0.0'}}),
22
+ );
23
+ fs.mkdirSync(path.join(project, 'src', 'app'), {recursive: true});
24
+ });
25
+ afterEach(() => { fs.rmSync(project, {recursive: true, force: true}); });
26
+ const block = '<!-- ASTRYX:START -->\nAstryx v0.7.0 · old\n<!-- ASTRYX:END -->\n';
27
+
28
+ it('removes from a subfolder what init wrote at the project root', async () => {
29
+ const sub = path.join(project, 'src', 'app');
30
+ const written = await init({features: ['agents']}, {cwd: sub});
31
+ expect(written.data.docsWritten).toEqual(['../../AGENTS.md', '../../GEMINI.md']);
32
+
33
+ const r = await remove({cwd: sub});
34
+ expect(r).toEqual({type: 'init.remove', data: {removed: true}});
35
+ // Both files held only what init wrote, so they are deleted.
36
+ expect(fs.existsSync(path.join(project, 'AGENTS.md'))).toBe(false);
37
+ expect(fs.existsSync(path.join(project, 'GEMINI.md'))).toBe(false);
38
+ expect((await remove({cwd: sub})).data.removed).toBe(false);
39
+ });
40
+
41
+ it('removes a block an earlier version left in the subfolder, and keeps the files\' own text', async () => {
42
+ const sub = path.join(project, 'src', 'app');
43
+ fs.writeFileSync(path.join(project, 'AGENTS.md'), `# Agents\n\nRoot rules.\n\n${block}`);
44
+ fs.writeFileSync(path.join(sub, 'AGENTS.md'), `# App\n\nApp rules.\n\n${block}`);
45
+
46
+ expect((await remove({cwd: sub})).data.removed).toBe(true);
47
+ expect(fs.readFileSync(path.join(project, 'AGENTS.md'), 'utf8').trimEnd()).toBe('# Agents\n\nRoot rules.');
48
+ expect(fs.readFileSync(path.join(sub, 'AGENTS.md'), 'utf8').trimEnd()).toBe('# App\n\nApp rules.');
49
+ });
50
+
51
+ it('run at the project root, leaves a subfolder alone', async () => {
52
+ const sub = path.join(project, 'src', 'app');
53
+ fs.writeFileSync(path.join(project, 'AGENTS.md'), `# Agents\n\n${block}`);
54
+ fs.writeFileSync(path.join(sub, 'AGENTS.md'), `# App\n\n${block}`);
55
+
56
+ expect((await remove({cwd: project})).data.removed).toBe(true);
57
+ expect(fs.readFileSync(path.join(sub, 'AGENTS.md'), 'utf8')).toContain('<!-- ASTRYX:START -->');
58
+ });
59
+
60
+ it('below the root, leaves a root agent file linked outside the project with a note, and removes the rest (0.7.x exited 0)', async () => {
61
+ // A workspace member whose CLAUDE.md links to the monorepo's.
62
+ const monorepo = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-rm-mono-'));
63
+ try {
64
+ const web = path.join(monorepo, 'apps', 'web');
65
+ const sub = path.join(web, 'src');
66
+ fs.mkdirSync(sub, {recursive: true});
67
+ fs.writeFileSync(
68
+ path.join(web, 'package.json'),
69
+ JSON.stringify({name: 'web', dependencies: {'@astryxdesign/core': '1.0.0'}}),
70
+ );
71
+ fs.writeFileSync(path.join(monorepo, 'CLAUDE.md'), `# Shared\n\n${block}`);
72
+ fs.symlinkSync('../../CLAUDE.md', path.join(web, 'CLAUDE.md'));
73
+ fs.writeFileSync(path.join(web, 'AGENTS.md'), `# Web\n\n${block}`);
74
+ fs.writeFileSync(path.join(sub, 'AGENTS.md'), `# Src\n\n${block}`);
75
+ const warned = [];
76
+ const warn = vi.spyOn(console, 'error').mockImplementation((...a) => warned.push(a.join(' ')));
77
+ logger.setSilent(false);
78
+ let r;
79
+ try {
80
+ r = await remove({cwd: sub});
81
+ } finally {
82
+ logger.setSilent(true);
83
+ warn.mockRestore();
84
+ }
85
+ expect(r).toEqual({type: 'init.remove', data: {removed: true}});
86
+ expect(fs.readFileSync(path.join(web, 'AGENTS.md'), 'utf8').trimEnd()).toBe('# Web');
87
+ expect(fs.readFileSync(path.join(sub, 'AGENTS.md'), 'utf8').trimEnd()).toBe('# Src');
88
+ // The file outside the project keeps its block.
89
+ expect(fs.readFileSync(path.join(monorepo, 'CLAUDE.md'), 'utf8')).toContain('<!-- ASTRYX:START -->');
90
+ expect(warned.join('\n')).toMatch(/Note: Left as it is: \.\.\/CLAUDE\.md \(/u);
91
+ } finally {
92
+ fs.rmSync(monorepo, {recursive: true, force: true});
93
+ }
94
+ });
95
+
96
+ it('at the root, a root agent file linked outside the project still refuses the run', async () => {
97
+ const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-rm-outside-'));
98
+ try {
99
+ fs.writeFileSync(path.join(outside, 'CLAUDE.md'), `# Shared\n\n${block}`);
100
+ fs.symlinkSync(path.join(outside, 'CLAUDE.md'), path.join(project, 'CLAUDE.md'));
101
+ fs.writeFileSync(path.join(project, 'AGENTS.md'), `# Agents\n\n${block}`);
102
+ await expect(remove({cwd: project})).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
103
+ expect(fs.readFileSync(path.join(project, 'AGENTS.md'), 'utf8')).toContain('<!-- ASTRYX:START -->');
104
+ } finally {
105
+ fs.rmSync(outside, {recursive: true, force: true});
106
+ }
107
+ });
108
+
109
+ it('a link in the subfolder that escapes it refuses the run before anything is written', async () => {
110
+ const sub = path.join(project, 'src', 'app');
111
+ const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-rm-outside-'));
112
+ try {
113
+ fs.writeFileSync(path.join(project, 'AGENTS.md'), `# Agents\n\n${block}`);
114
+ fs.writeFileSync(path.join(outside, 'CLAUDE.md'), `# Shared\n\n${block}`);
115
+ fs.symlinkSync(path.join(outside, 'CLAUDE.md'), path.join(sub, 'CLAUDE.md'));
116
+
117
+ await expect(remove({cwd: sub})).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
118
+ expect(fs.readFileSync(path.join(project, 'AGENTS.md'), 'utf8')).toContain('<!-- ASTRYX:START -->');
119
+ expect(fs.readFileSync(path.join(outside, 'CLAUDE.md'), 'utf8')).toContain('<!-- ASTRYX:START -->');
120
+ } finally {
121
+ fs.rmSync(outside, {recursive: true, force: true});
122
+ }
123
+ });
124
+ });
@@ -4,10 +4,12 @@
4
4
  * @file init.run leaf — non-interactive project setup + feature installer.
5
5
  *
6
6
  * `run(options, ctx)` is the default / `--features` / `--all` path behind
7
- * `astryx init`. It installs the AGENTS.md/CLAUDE.md agent-docs cheat sheet,
8
- * points at the theme + page-building workflows, and (optionally) scaffolds a
9
- * starter template — with NO prompts, so it behaves identically for humans,
10
- * agents, CI, and piped I/O. It performs the side effects and returns an
7
+ * `astryx init`. It installs the agent-docs cheat sheet at the project root so
8
+ * every agent reads it (AGENTS.md, a copy in the project's Claude Code file, and
9
+ * a GEMINI.md import), points at the theme + page-building workflows, and
10
+ * (optionally) scaffolds a starter template — with NO prompts, so it behaves
11
+ * identically for humans, agents, CI, and piped I/O. It performs the side
12
+ * effects and returns an
11
13
  * `init.run` receipt. Hard errors (unknown feature/template) throw AstryxError
12
14
  * with a stable code. Human output is emitted through the shared `logger`
13
15
  * (silent by default) so the CLI keeps its exact plain output and a
@@ -21,8 +23,11 @@ import {PathSafetyError, assertWithin} from '../../../foundation/fs/path-safety.
21
23
  import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
22
24
  import {isOutsideProject} from '../../../foundation/env/project-scope.mjs';
23
25
  import {
26
+ AgentDocsHomeError,
27
+ assertAgentDocsTarget,
24
28
  installAgentDocs,
25
29
  renderAgentDocsBlock,
30
+ agentDocsTargetDir,
26
31
  } from '../../../foundation/agent-docs/agent-docs.mjs';
27
32
  import {themeTemplate} from '../../theme/template/template.mjs';
28
33
  import {listTemplates} from '../../template/template.mjs';
@@ -64,6 +69,24 @@ export function getNextSteps(invocation) {
64
69
  ];
65
70
  }
66
71
 
72
+ /**
73
+ * Whether two paths name one folder, links resolved.
74
+ * @param {string} a
75
+ * @param {string} b
76
+ * @returns {boolean}
77
+ */
78
+ function sameFolder(a, b) {
79
+ /** @param {string} p */
80
+ const real = p => {
81
+ try {
82
+ return fs.realpathSync(p);
83
+ } catch {
84
+ return path.resolve(p);
85
+ }
86
+ };
87
+ return real(a) === real(b);
88
+ }
89
+
67
90
  /**
68
91
  * Install the agent-docs block; records the outcome (or soft error) on `data`.
69
92
  * Mirrors the CLI's historical soft-error policy: a PathSafetyError surfaces its
@@ -92,14 +115,46 @@ async function applyAgents(cwd, options, invocation, data) {
92
115
  ? options.agentDocsPath
93
116
  : [options.agentDocsPath]
94
117
  : undefined;
95
- const renderedBlock = await renderAgentDocsBlock(cwd);
96
- const written = installAgentDocs(cwd, {
118
+ // The docs belong at the project root, not in the subfolder init ran in;
119
+ // with no project above, they go where init ran, as before. Explicit
120
+ // --agent-docs-path entries stay relative to where init ran.
121
+ const root = agentDocsTargetDir(cwd);
122
+ const targetDir = paths ? cwd : root;
123
+ // With explicit paths, installAgentDocs checks each file's own folder.
124
+ if (!paths) assertAgentDocsTarget(targetDir);
125
+ const renderedBlock = await renderAgentDocsBlock(root);
126
+ /** @type {string[]} */
127
+ const skipped = [];
128
+ const files = installAgentDocs(targetDir, {
97
129
  agent: options.agent,
98
130
  paths,
99
131
  renderedBlock,
132
+ onSkipped: (rel, reason) => skipped.push(`${rel} (${reason})`),
133
+ // Below the project root, 0.7.1 wrote in the folder init ran in, so a
134
+ // project-root file that escapes the project is skipped and reported,
135
+ // not refused.
136
+ refuseEscapes: sameFolder(targetDir, cwd),
100
137
  });
138
+ // Each file is reported from where init ran, as before.
139
+ const written =
140
+ path.resolve(targetDir) === path.resolve(cwd)
141
+ ? files
142
+ : files.map(rel =>
143
+ path.relative(cwd, path.join(targetDir, rel)).split(path.sep).join('/'),
144
+ );
101
145
  data.docsWritten = written;
102
146
  logger.log(`[ok] AI agent docs installed -> ${written.join(', ')}`);
147
+ // A file 0.7.1 did not write (GEMINI.md, or a project-root file when init
148
+ // runs below the root) that resolves outside the project is left as it
149
+ // is, reported in docsError with one note; the exit code stays 0. A file
150
+ // 0.7.1 wrote whose path escapes the project still fails the run (below).
151
+ if (skipped.length > 0) {
152
+ const message =
153
+ `Left as ${skipped.length === 1 ? 'it is' : 'they are'}: ${skipped.join('; ')}. ` +
154
+ 'To have init write the Astryx block there, make it a regular file inside the project, or copy the block from AGENTS.md by hand.';
155
+ logger.warn(`Note: ${message}`);
156
+ data.docsError = {kind: 'install-failed', message};
157
+ }
103
158
  } catch (err) {
104
159
  // PathSafetyError carries a precise, user-actionable message — surface it
105
160
  // (and flag exit 1) instead of the generic "could not install" warning so
@@ -109,6 +164,14 @@ async function applyAgents(cwd, options, invocation, data) {
109
164
  data.docsError = {kind: 'path-safety', message: err.message};
110
165
  return;
111
166
  }
167
+ // The home folder, and a settings folder in it outside a project, are
168
+ // refused: nothing is written, the reason is printed as a note, and the
169
+ // exit code stays 0.
170
+ if (err instanceof AgentDocsHomeError) {
171
+ logger.warn(`Note: ${err.message}`);
172
+ data.docsError = {kind: 'install-failed', message: err.message};
173
+ return;
174
+ }
112
175
  logger.error(
113
176
  `Could not install agent docs. Try again with \`${invocation} init --features agents\`.`,
114
177
  );
@@ -40,6 +40,14 @@ export function integrationFluff(discovered: Parameters<typeof findFluff>[0]): P
40
40
  * read too
41
41
  */
42
42
  export function integrationStrayPointers(discovered: Parameters<typeof findStrayPointers>[0], integration?: any): Promise<import("./authoring-checks.type.mjs").StrayPointer[]>;
43
+ /**
44
+ * Each Astryx command a package's topics write with a package runner. A
45
+ * package whose topics cannot be discovered has none here: the other checks
46
+ * report topics that do not load.
47
+ * @param {any} integration a loaded integration
48
+ * @returns {Promise<import('../../foundation/discovery/runner-commands.mjs').RunnerCommand[]>}
49
+ */
50
+ export function integrationRunnerCommands(integration: any): Promise<import("../../foundation/discovery/runner-commands.mjs").RunnerCommand[]>;
43
51
  import { findCopiedPassages } from '../../foundation/discovery/copied-passages.mjs';
44
52
  import { findFluff } from '../../foundation/discovery/doc-fluff.mjs';
45
53
  import { findStrayPointers } from '../../foundation/discovery/stray-pointers.mjs';
@@ -2,7 +2,8 @@
2
2
 
3
3
  /**
4
4
  * @file The integration subject's access to the environment (INV21): reading
5
- * one package's component docs and sources with the project's own TypeScript.
5
+ * one package's component docs and sources with the project's own TypeScript,
6
+ * and its topics.
6
7
  *
7
8
  * @input a loaded integration and the directory the command runs in
8
9
  * @output the reports the integration checks attach to their results
@@ -14,9 +15,11 @@ import {
14
15
  forEachIntegrationDoc,
15
16
  integrationSourceForDoc,
16
17
  } from '../../foundation/discovery/component-discovery.mjs';
18
+ import {discoverIntegrationDocs} from '../../foundation/discovery/docs-discovery.mjs';
17
19
  import {comparePropDocs} from '../../foundation/discovery/prop-drift.mjs';
18
20
  import {findCopiedPassages} from '../../foundation/discovery/copied-passages.mjs';
19
21
  import {findFluff} from '../../foundation/discovery/doc-fluff.mjs';
22
+ import {findRunnerCommands} from '../../foundation/discovery/runner-commands.mjs';
20
23
  import {findStrayPointers} from '../../foundation/discovery/stray-pointers.mjs';
21
24
 
22
25
  /**
@@ -110,3 +113,20 @@ export async function integrationStrayPointers(discovered, integration) {
110
113
  }
111
114
  return findStrayPointers({...discovered, components});
112
115
  }
116
+
117
+ /**
118
+ * Each Astryx command a package's topics write with a package runner. A
119
+ * package whose topics cannot be discovered has none here: the other checks
120
+ * report topics that do not load.
121
+ * @param {any} integration a loaded integration
122
+ * @returns {Promise<import('../../foundation/discovery/runner-commands.mjs').RunnerCommand[]>}
123
+ */
124
+ export async function integrationRunnerCommands(integration) {
125
+ let discovered;
126
+ try {
127
+ discovered = await discoverIntegrationDocs(integration);
128
+ } catch {
129
+ return [];
130
+ }
131
+ return findRunnerCommands(discovered);
132
+ }
@@ -14,6 +14,7 @@ vi.mock('../../foundation/discovery/template-conflict-release.mjs', () => ({
14
14
  }));
15
15
  import * as fs from 'node:fs';
16
16
  import * as path from 'node:path';
17
+ import {validateIntegration} from './validate-integration.mjs';
17
18
  import {discoverCoreTemplates} from '../../foundation/discovery/template-adapter.mjs';
18
19
  import {discoverOwnedComponents} from '../../foundation/discovery/component-discovery.mjs';
19
20
  import {discoverBuiltinTopics} from '../../foundation/discovery/docs-discovery.mjs';
@@ -1331,3 +1332,222 @@ describe('links in component docs and topic descriptions', () => {
1331
1332
  ]);
1332
1333
  });
1333
1334
  });
1335
+
1336
+ describe('validateIntegration runner-command notes', () => {
1337
+ /** The runner-command notes, read back into their parts. */
1338
+ async function runnerNotes() {
1339
+ const {data} = await validateIntegration(undefined, {cwd: tmpDir});
1340
+ const notes = (data.notes ?? [])
1341
+ .filter((/** @type {any} */ note) => note.code === 'runner_command')
1342
+ .map((/** @type {any} */ note) => {
1343
+ const m =
1344
+ /^(\S+): "([^"]+)"(?: \(section "([^"]+)"\))? writes `([^`]+)`(?: \(line (\d+)\))?\./.exec(
1345
+ note.message,
1346
+ );
1347
+ return {
1348
+ file: m?.[1],
1349
+ topic: m?.[2],
1350
+ section: m?.[3] ?? null,
1351
+ command: m?.[4],
1352
+ line: m?.[5] ? Number(m[5]) : null,
1353
+ message: note.message,
1354
+ };
1355
+ });
1356
+ return {data, notes};
1357
+ }
1358
+
1359
+ function writeTopic(/** @type {string} */ text) {
1360
+ fs.writeFileSync(
1361
+ path.join(tmpDir, 'package.json'),
1362
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1363
+ );
1364
+ fs.writeFileSync(
1365
+ path.join(tmpDir, 'astryx.integration.mjs'),
1366
+ `export default {docs: './docs'};\n`,
1367
+ );
1368
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1369
+ const doc = {
1370
+ type: 'generic',
1371
+ name: 'acme-setup',
1372
+ title: 'Fixture',
1373
+ description: 'Fixture topic.',
1374
+ sections: [
1375
+ {
1376
+ title: 'Overview',
1377
+ content: [
1378
+ {type: 'prose', text},
1379
+ {type: 'code', lang: 'bash', code: 'npx @astryxdesign/cli init'},
1380
+ ],
1381
+ },
1382
+ ],
1383
+ };
1384
+ fs.writeFileSync(
1385
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1386
+ `export default ${JSON.stringify(doc)};\n`,
1387
+ );
1388
+ }
1389
+
1390
+ it('lists a runner command with its line and fix, and raises no issue', async () => {
1391
+ writeTopic('Check it with `pnpm exec astryx doctor` first.');
1392
+
1393
+ const {data, notes} = await runnerNotes();
1394
+ const [hit, ...rest] = notes;
1395
+
1396
+ expect(rest).toEqual([]);
1397
+ expect(hit).toMatchObject({
1398
+ topic: 'acme-setup',
1399
+ section: 'Overview',
1400
+ file: 'docs/acme-setup.doc.mjs',
1401
+ line: 1,
1402
+ command: 'pnpm exec astryx doctor',
1403
+ });
1404
+ expect(hit.message).toContain('Write `astryx doctor`');
1405
+ // A note only: no issue, so no exit changes on it.
1406
+ expect(
1407
+ data.issues.map((/** @type {any} */ issue) => issue.code),
1408
+ ).not.toContain('runner_command');
1409
+ });
1410
+
1411
+ it('puts each copy of a repeated command on its own line', async () => {
1412
+ fs.writeFileSync(
1413
+ path.join(tmpDir, 'package.json'),
1414
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1415
+ );
1416
+ fs.writeFileSync(
1417
+ path.join(tmpDir, 'astryx.integration.mjs'),
1418
+ `export default {docs: './docs'};\n`,
1419
+ );
1420
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1421
+ const doc = {
1422
+ type: 'generic',
1423
+ name: 'acme-setup',
1424
+ title: 'Fixture',
1425
+ description: 'Fixture topic.',
1426
+ sections: [
1427
+ {
1428
+ title: 'First',
1429
+ content: [{type: 'prose', text: 'Run `npx astryx doctor`.'}],
1430
+ },
1431
+ {
1432
+ title: 'Second',
1433
+ content: [{type: 'prose', text: 'Run `npx astryx doctor` again.'}],
1434
+ },
1435
+ {
1436
+ title: 'Third',
1437
+ content: [{type: 'prose', text: 'Or plain `npx astryx`.'}],
1438
+ },
1439
+ ],
1440
+ };
1441
+ fs.writeFileSync(
1442
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1443
+ `export default ${JSON.stringify(doc, null, 2)};\n`,
1444
+ );
1445
+ const lines = fs
1446
+ .readFileSync(path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'), 'utf8')
1447
+ .split('\n');
1448
+ const lineHolding = (/** @type {string} */ text) =>
1449
+ lines.findIndex(line => line.includes(text)) + 1;
1450
+
1451
+ const {notes} = await runnerNotes();
1452
+
1453
+ expect(
1454
+ notes.map((/** @type {any} */ each) => [
1455
+ each.section,
1456
+ each.line,
1457
+ each.command,
1458
+ ]),
1459
+ ).toEqual([
1460
+ ['First', lineHolding('Run `npx astryx doctor`.'), 'npx astryx doctor'],
1461
+ ['Second', lineHolding('again.'), 'npx astryx doctor'],
1462
+ ['Third', lineHolding('Or plain'), 'npx astryx'],
1463
+ ]);
1464
+ });
1465
+
1466
+ it('puts each copy of an identical one-line string on its own line', async () => {
1467
+ fs.writeFileSync(
1468
+ path.join(tmpDir, 'package.json'),
1469
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1470
+ );
1471
+ fs.writeFileSync(
1472
+ path.join(tmpDir, 'astryx.integration.mjs'),
1473
+ `export default {docs: './docs'};\n`,
1474
+ );
1475
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1476
+ const block = {type: 'code', lang: 'bash', code: 'npx astryx doctor'};
1477
+ const doc = {
1478
+ type: 'generic',
1479
+ name: 'acme-setup',
1480
+ title: 'Fixture',
1481
+ description: 'Fixture topic.',
1482
+ sections: [
1483
+ {title: 'First', content: [block]},
1484
+ {title: 'Second', content: [block]},
1485
+ ],
1486
+ };
1487
+ fs.writeFileSync(
1488
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1489
+ `export default ${JSON.stringify(doc, null, 2)};\n`,
1490
+ );
1491
+ const lines = fs
1492
+ .readFileSync(path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'), 'utf8')
1493
+ .split('\n');
1494
+ const copies = lines.flatMap((line, at) =>
1495
+ line.includes('"npx astryx doctor"') ? [at + 1] : [],
1496
+ );
1497
+
1498
+ const {notes} = await runnerNotes();
1499
+
1500
+ expect(copies).toHaveLength(2);
1501
+ expect(
1502
+ notes.map((/** @type {any} */ each) => [each.section, each.line]),
1503
+ ).toEqual([
1504
+ ['First', copies[0]],
1505
+ ['Second', copies[1]],
1506
+ ]);
1507
+ });
1508
+
1509
+ it("places a section's command on its own line when the section sits in a constant above the doc", async () => {
1510
+ fs.writeFileSync(
1511
+ path.join(tmpDir, 'package.json'),
1512
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1513
+ );
1514
+ fs.writeFileSync(
1515
+ path.join(tmpDir, 'astryx.integration.mjs'),
1516
+ `export default {docs: './docs'};\n`,
1517
+ );
1518
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1519
+ fs.writeFileSync(
1520
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1521
+ [
1522
+ "const install = {title: 'Install', content: [{type: 'prose', text: 'Run `npx astryx doctor`.'}]};",
1523
+ '',
1524
+ 'export default {',
1525
+ " type: 'generic',",
1526
+ " name: 'acme-setup',",
1527
+ " title: 'Fixture',",
1528
+ " description: 'Install first: `npx astryx doctor`.',",
1529
+ ' sections: [install],',
1530
+ '};',
1531
+ '',
1532
+ ].join('\n'),
1533
+ );
1534
+
1535
+ const {notes} = await runnerNotes();
1536
+
1537
+ expect(
1538
+ notes.map((/** @type {any} */ each) => [each.section, each.line]),
1539
+ ).toEqual(
1540
+ expect.arrayContaining([
1541
+ [null, 7],
1542
+ ['Install', 1],
1543
+ ]),
1544
+ );
1545
+ });
1546
+
1547
+ it('lists nothing for bare commands and the scoped install step', async () => {
1548
+ writeTopic('Check it with `astryx doctor` first.');
1549
+
1550
+ const {notes} = await runnerNotes();
1551
+ expect((await runnerNotes()).notes).toEqual([]);
1552
+ });
1553
+ });