@astryxdesign/cli 0.6.3-canary.98a2e4e → 0.6.3-canary.a860a50

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 (291) hide show
  1. package/README.md +32 -18
  2. package/api/build/build.doc.mjs +3 -3
  3. package/api/build/build.test.mjs +14 -3
  4. package/api/build/build.type.d.mts +36 -2
  5. package/api/build/build.type.mjs +25 -4
  6. package/api/build/help/help.d.mts +8 -5
  7. package/api/build/help/help.mjs +56 -6
  8. package/api/component/component.doc.mjs +11 -2
  9. package/api/component/component.mjs +29 -0
  10. package/api/component/component.test.mjs +38 -0
  11. package/api/component/component.type.d.mts +17 -7
  12. package/api/component/component.type.mjs +27 -20
  13. package/api/discover/discover.doc.mjs +1 -1
  14. package/api/discover/discover.type.d.mts +4 -4
  15. package/api/discover/discover.type.mjs +10 -10
  16. package/api/docs/_adapter.d.mts +30 -27
  17. package/api/docs/_adapter.mjs +154 -124
  18. package/api/docs/compiled-topics.test.mjs +78 -0
  19. package/api/docs/detail/detail.d.mts +0 -15
  20. package/api/docs/detail/detail.mjs +14 -78
  21. package/api/docs/detail/section/section.mjs +22 -18
  22. package/api/docs/detail/section/section.test.mjs +4 -3
  23. package/api/docs/docs.type.d.mts +4 -4
  24. package/api/docs/docs.type.mjs +10 -10
  25. package/api/docs/index/index.mjs +6 -5
  26. package/api/doctor/doctor.mjs +3 -7
  27. package/api/gap-report/gap-report.doc.mjs +7 -4
  28. package/api/hook/hook.type.d.mts +3 -3
  29. package/api/hook/hook.type.mjs +11 -11
  30. package/api/init/init.doc.mjs +4 -0
  31. package/api/init/init.test.mjs +41 -1
  32. package/api/init/remove/remove.mjs +1 -1
  33. package/api/init/run/run.mjs +20 -10
  34. package/api/integration/add-contribution.component-names.test.mjs +120 -0
  35. package/api/integration/add-contribution.mjs +16 -3
  36. package/api/integration/add-contribution.test.mjs +84 -4
  37. package/api/integration/integrationAdd.doc.mjs +7 -4
  38. package/api/integration/integrationAddComponent.doc.mjs +1 -1
  39. package/api/integration/pack-check.mjs +49 -7
  40. package/api/integration/pack-check.test.mjs +249 -0
  41. package/api/integration/validate-integration.mjs +2 -0
  42. package/api/integration/validate-integration.test.mjs +91 -0
  43. package/api/integration/validateIntegration.doc.mjs +1 -1
  44. package/api/json/envelope-types.test.mjs +76 -0
  45. package/api/json/parseResponse.doc.mjs +2 -2
  46. package/api/layout/expand/expand.mjs +7 -5
  47. package/api/layout/expand/expand.path-safety.test.mjs +53 -0
  48. package/api/layout/grammar/grammar.mjs +2 -1
  49. package/api/layout/layoutExpand.doc.mjs +1 -1
  50. package/api/search/search-return-type.test.mjs +54 -0
  51. package/api/search/search.d.mts +2 -9
  52. package/api/search/search.doc.mjs +5 -1
  53. package/api/search/search.mjs +15 -8
  54. package/api/search/search.test.mjs +34 -0
  55. package/api/search/search.type.d.mts +1 -1
  56. package/api/search/search.type.mjs +1 -1
  57. package/api/swizzle/copy/copy.mjs +28 -11
  58. package/api/swizzle/swizzle.doc.mjs +1 -1
  59. package/api/swizzle/swizzle.type.d.mts +2 -2
  60. package/api/swizzle/swizzle.type.mjs +2 -2
  61. package/api/template/copy/copy.mjs +17 -23
  62. package/api/template/copy/copy.test.mjs +17 -0
  63. package/api/template/template.doc.mjs +2 -1
  64. package/api/template/template.type.d.mts +5 -5
  65. package/api/template/template.type.mjs +12 -12
  66. package/api/theme/add/add.binary.test.mjs +91 -0
  67. package/api/theme/add/add.mjs +15 -2
  68. package/api/theme/build/build.mjs +133 -42
  69. package/api/theme/build/build.public-component-vars.test.mjs +1 -1
  70. package/api/theme/build/build.receipt-doc.test.mjs +111 -0
  71. package/api/theme/build/build.test.mjs +127 -0
  72. package/api/theme/build/font-warning.mjs +3 -3
  73. package/api/theme/build/font-warning.test.mjs +5 -2
  74. package/api/theme/palette/generate/generate.mjs +8 -3
  75. package/api/theme/palette/generate/generate.test.mjs +96 -0
  76. package/api/theme/palette/generate/generator.d.mts +10 -13
  77. package/api/theme/palette/generate/generator.mjs +15 -4
  78. package/api/theme/palette/generate/generator.test.mjs +10 -0
  79. package/api/theme/template/template.mjs +11 -2
  80. package/api/theme/template/template.test.mjs +15 -0
  81. package/api/theme/theme.type.d.mts +170 -11
  82. package/api/theme/theme.type.mjs +94 -27
  83. package/api/theme/themeBuild.doc.mjs +7 -4
  84. package/api/theme/themeTemplate.doc.mjs +4 -1
  85. package/api/upgrade/_adapter.mjs +27 -4
  86. package/api/upgrade/list/list.mjs +2 -1
  87. package/api/upgrade/list/list.test.mjs +73 -0
  88. package/api/upgrade/status/status.mjs +2 -2
  89. package/api/upgrade/upgrade.doc.mjs +2 -1
  90. package/api/upgrade/upgrade.type.d.mts +8 -4
  91. package/api/upgrade/upgrade.type.mjs +11 -10
  92. package/assets/codemods/integration-discovery.mjs +40 -2
  93. package/assets/codemods/integration-discovery.test.mjs +58 -0
  94. package/assets/codemods/term-log.mjs +32 -8
  95. package/assets/codemods/term-log.test.mjs +19 -1
  96. package/assets/codemods/transforms/v0.3.0/__tests__/unwrap-authoring-factories.test.mjs +27 -5
  97. package/assets/codemods/transforms/v0.3.0/unwrap-authoring-factories.mjs +20 -5
  98. package/assets/codemods/transforms/v0.6.0/__tests__/next-codemods.test.mjs +47 -0
  99. package/assets/codemods/transforms/v0.6.0/rename-resizable-pixel-bounds.mjs +57 -10
  100. package/assets/docs/cli-integrations.doc.mjs +9 -0
  101. package/assets/docs/styling-libraries.doc.mjs +1 -1
  102. package/assets/docs/working-with-ai.doc.mjs +1 -1
  103. package/assets/templates/pages/table-tree/page.tsx +1704 -0
  104. package/assets/templates/pages/table-tree/template.doc.mjs +12 -0
  105. package/authoring/_shared/contract.ts +22 -0
  106. package/authoring/codemod/codemod.doc.mjs +6 -1
  107. package/authoring/codemod/parse.d.mts +8 -8
  108. package/authoring/codemod/parse.mjs +8 -6
  109. package/authoring/config/config.doc.mjs +1 -1
  110. package/authoring/config/debug-composition.test.mjs +92 -0
  111. package/authoring/config/parse.d.mts +13 -13
  112. package/authoring/config/parse.mjs +8 -8
  113. package/authoring/config/type.ts +18 -6
  114. package/authoring/debug/parse.d.mts +4 -4
  115. package/authoring/debug/parse.mjs +3 -3
  116. package/authoring/doctypes/_schema.d.mts +121 -11
  117. package/authoring/doctypes/_schema.mjs +144 -13
  118. package/authoring/doctypes/base/graph-fields.doc.mjs +11 -4
  119. package/authoring/doctypes/base/type.ts +8 -4
  120. package/authoring/doctypes/command/command.doc.mjs +3 -2
  121. package/authoring/doctypes/command/parse.d.mts +2 -2
  122. package/authoring/doctypes/command/parse.mjs +1 -1
  123. package/authoring/doctypes/command/type.ts +2 -2
  124. package/authoring/doctypes/component/component.doc.mjs +5 -2
  125. package/authoring/doctypes/component/parse.d.mts +2 -2
  126. package/authoring/doctypes/component/parse.mjs +1 -1
  127. package/authoring/doctypes/component/type.ts +1 -1
  128. package/authoring/doctypes/enum/parse.d.mts +2 -2
  129. package/authoring/doctypes/enum/parse.mjs +1 -1
  130. package/authoring/doctypes/enum/type.ts +1 -1
  131. package/authoring/doctypes/function/function.doc.mjs +4 -0
  132. package/authoring/doctypes/function/parse.d.mts +2 -2
  133. package/authoring/doctypes/function/parse.mjs +1 -1
  134. package/authoring/doctypes/function/type.ts +1 -1
  135. package/authoring/doctypes/hook/hook.doc.mjs +4 -0
  136. package/authoring/doctypes/hook/parse.d.mts +2 -2
  137. package/authoring/doctypes/hook/parse.mjs +1 -1
  138. package/authoring/doctypes/hook/type.ts +1 -1
  139. package/authoring/doctypes/legacy.d.mts +6 -6
  140. package/authoring/doctypes/legacy.mjs +3 -3
  141. package/authoring/doctypes/load-contract.test.mjs +207 -0
  142. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -3
  143. package/authoring/doctypes/namespace/parse.d.mts +2 -2
  144. package/authoring/doctypes/namespace/parse.mjs +1 -1
  145. package/authoring/doctypes/namespace/type.ts +2 -2
  146. package/authoring/doctypes/parse.d.mts +18 -18
  147. package/authoring/doctypes/parse.mjs +9 -9
  148. package/authoring/doctypes/reference/parse.d.mts +2 -2
  149. package/authoring/doctypes/reference/parse.mjs +1 -1
  150. package/authoring/doctypes/reference/reference.doc.mjs +6 -2
  151. package/authoring/doctypes/reference/type.ts +1 -1
  152. package/authoring/doctypes/schema/parse.d.mts +2 -2
  153. package/authoring/doctypes/schema/parse.mjs +1 -1
  154. package/authoring/doctypes/schema/type.ts +2 -2
  155. package/authoring/doctypes/template/parse.d.mts +92 -1
  156. package/authoring/doctypes/template/parse.mjs +33 -1
  157. package/authoring/doctypes/template/template.doc.mjs +4 -0
  158. package/authoring/doctypes/template/type.ts +4 -1
  159. package/authoring/doctypes/types.ts +10 -10
  160. package/authoring/gap-report/parse.d.mts +9 -9
  161. package/authoring/gap-report/parse.mjs +6 -6
  162. package/authoring/gap-report/type.ts +1 -1
  163. package/authoring/identity/identity.doc.mjs +3 -2
  164. package/authoring/identity/type.ts +10 -10
  165. package/authoring/index.d.ts +19 -19
  166. package/authoring/integration/parse.d.mts +2 -2
  167. package/authoring/integration/parse.mjs +1 -1
  168. package/authoring/integration/schema.d.mts +4 -4
  169. package/authoring/integration/schema.mjs +3 -3
  170. package/authoring/integration/type.ts +1 -1
  171. package/clients/cli/command-load-failure.test.mjs +83 -0
  172. package/clients/cli/commands/blog.mjs +23 -8
  173. package/clients/cli/commands/blog.test.mjs +42 -1
  174. package/clients/cli/commands/build-theme.ascii-output.test.mjs +161 -0
  175. package/clients/cli/commands/build-theme.flag-docs.test.mjs +110 -0
  176. package/clients/cli/commands/build-theme.mjs +5 -5
  177. package/clients/cli/commands/build-theme.path-safety.test.mjs +86 -1
  178. package/clients/cli/commands/build-theme.variants.test.mjs +76 -0
  179. package/clients/cli/commands/build.doc.mjs +4 -1
  180. package/clients/cli/commands/build.exit-codes-doc.test.mjs +50 -0
  181. package/clients/cli/commands/build.mjs +32 -47
  182. package/clients/cli/commands/build.playbook.test.mjs +75 -0
  183. package/clients/cli/commands/build.text-fields.test.mjs +40 -0
  184. package/clients/cli/commands/component/index.mjs +2 -7
  185. package/clients/cli/commands/component-package.test.mjs +18 -0
  186. package/clients/cli/commands/component-resolution.test.mjs +21 -0
  187. package/clients/cli/commands/component.test.mjs +19 -0
  188. package/clients/cli/commands/detail-levels.test.mjs +2 -2
  189. package/clients/cli/commands/discover.broken-integration.test.mjs +48 -0
  190. package/clients/cli/commands/discover.components-flag.test.mjs +97 -0
  191. package/clients/cli/commands/discover.doc.mjs +4 -2
  192. package/clients/cli/commands/discover.mjs +3 -3
  193. package/clients/cli/commands/discover.text-projection.test.mjs +103 -0
  194. package/clients/cli/commands/doctor-integration.package-json.test.mjs +53 -0
  195. package/clients/cli/commands/doctor.mjs +6 -16
  196. package/clients/cli/commands/doctor.test.mjs +42 -0
  197. package/clients/cli/commands/gap-report.doc.mjs +16 -5
  198. package/clients/cli/commands/gap-report.test.mjs +72 -0
  199. package/clients/cli/commands/hook/index.mjs +7 -17
  200. package/clients/cli/commands/hook.text-projection.test.mjs +45 -0
  201. package/clients/cli/commands/init.doc.mjs +19 -8
  202. package/clients/cli/commands/init.flag-help.test.mjs +153 -0
  203. package/clients/cli/commands/integration-add.controls.test.mjs +132 -0
  204. package/clients/cli/commands/integration-add.doc.mjs +21 -5
  205. package/clients/cli/commands/integration-authoring.test.mjs +13 -9
  206. package/clients/cli/commands/interactive-guard.test.mjs +101 -24
  207. package/clients/cli/commands/json-contract.test.mjs +33 -0
  208. package/clients/cli/commands/layout-check.doc.mjs +14 -3
  209. package/clients/cli/commands/layout-expand.doc.mjs +21 -4
  210. package/clients/cli/commands/layout.doc.mjs +2 -2
  211. package/clients/cli/commands/layout.mjs +21 -9
  212. package/clients/cli/commands/layout.path-help.test.mjs +33 -0
  213. package/clients/cli/commands/layout.stdin-cap.test.mjs +47 -0
  214. package/clients/cli/commands/layout.text-fields.test.mjs +39 -0
  215. package/clients/cli/commands/no-prompt-wording.test.mjs +94 -0
  216. package/clients/cli/commands/search.doc.mjs +5 -2
  217. package/clients/cli/commands/search.mjs +13 -2
  218. package/clients/cli/commands/search.test.mjs +61 -0
  219. package/clients/cli/commands/swizzle.doc.mjs +2 -1
  220. package/clients/cli/commands/swizzle.path-safety.test.mjs +42 -0
  221. package/clients/cli/commands/template.doc.mjs +28 -6
  222. package/clients/cli/commands/template.flag-help.test.mjs +117 -0
  223. package/clients/cli/commands/template.path-help.test.mjs +40 -0
  224. package/clients/cli/commands/theme-add.doc.mjs +2 -1
  225. package/clients/cli/commands/theme-build.doc.mjs +7 -6
  226. package/clients/cli/commands/theme-palette-generate.test.mjs +19 -0
  227. package/clients/cli/commands/theme-template.behavior.test.mjs +12 -0
  228. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  229. package/clients/cli/commands/upgrade.ascii-output.test.mjs +87 -0
  230. package/clients/cli/commands/upgrade.doc.mjs +17 -6
  231. package/clients/cli/commands/upgrade.flag-help.test.mjs +188 -0
  232. package/clients/cli/commands/upgrade.hook-output.test.mjs +88 -0
  233. package/clients/cli/index.mjs +13 -30
  234. package/clients/cli/latest-version-env.test.mjs +50 -0
  235. package/clients/cli/lib/cli-error.test.mjs +7 -0
  236. package/clients/cli/lib/component-format.mjs +9 -9
  237. package/clients/cli/lib/component-format.test.mjs +1 -1
  238. package/clients/cli/lib/define-command.mjs +32 -6
  239. package/clients/cli/lib/doc-text-ascii.test.mjs +82 -0
  240. package/clients/cli/lib/exit-codes.test.mjs +97 -0
  241. package/clients/cli/lib/hook-format.mjs +5 -5
  242. package/clients/cli/lib/json-shim.mjs +38 -2
  243. package/clients/cli/lib/json-shim.test.mjs +83 -0
  244. package/clients/cli/lib/manifest.d.ts +2 -0
  245. package/clients/cli/lib/manifest.mjs +22 -0
  246. package/clients/cli/lib/manifest.test.mjs +17 -0
  247. package/foundation/agent-docs/agent-docs.d.mts +4 -0
  248. package/foundation/agent-docs/agent-docs.mjs +69 -3
  249. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +266 -4
  250. package/foundation/config/integration-debug.test.mjs +28 -3
  251. package/foundation/config/project.mjs +123 -9
  252. package/foundation/config/project.test.mjs +126 -0
  253. package/foundation/discovery/authoring-self-docs.test.mjs +71 -12
  254. package/foundation/discovery/docs-discovery.d.mts +4 -0
  255. package/foundation/discovery/docs-discovery.mjs +16 -2
  256. package/foundation/discovery/docs-discovery.test.mjs +47 -11
  257. package/foundation/discovery/template-adapter.d.mts +14 -5
  258. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +248 -0
  259. package/foundation/discovery/template-adapter.integration-isolation.test.mjs +94 -0
  260. package/foundation/discovery/template-adapter.mjs +292 -25
  261. package/foundation/discovery/theming-targets.test.mjs +4 -0
  262. package/foundation/doc-compiler/compile.d.mts +162 -0
  263. package/foundation/doc-compiler/compile.mjs +262 -0
  264. package/foundation/doc-compiler/doc-compiler.test.mjs +687 -0
  265. package/foundation/doc-compiler/ir.d.mts +9 -0
  266. package/foundation/doc-compiler/ir.mjs +287 -0
  267. package/foundation/doc-compiler/lenses.d.mts +33 -0
  268. package/foundation/doc-compiler/lenses.mjs +127 -0
  269. package/foundation/fs/module-loader.d.mts +1 -0
  270. package/foundation/fs/module-loader.mjs +50 -1
  271. package/foundation/fs/module-loader.stdout.test.mjs +332 -0
  272. package/foundation/fs/path-safety.d.mts +3 -2
  273. package/foundation/fs/path-safety.mjs +49 -19
  274. package/foundation/fs/path-safety.test.mjs +50 -0
  275. package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +129 -94
  276. package/foundation/integrations/autolink.mjs +6 -1
  277. package/foundation/response/base.d.ts +8 -4
  278. package/foundation/response/error-codes.doc.mjs +1 -2
  279. package/foundation/response/error-codes.mjs +1 -1
  280. package/foundation/response/error-codes.test.mjs +83 -0
  281. package/foundation/response/json-contract.test.mjs +11 -0
  282. package/foundation/response/json.d.mts +4 -2
  283. package/foundation/response/json.mjs +8 -10
  284. package/foundation/response/response-types.doc.mjs +3 -3
  285. package/foundation/xle/expand.d.mts +2 -0
  286. package/foundation/xle/expand.mjs +3 -2
  287. package/foundation/xle/expand.test.mjs +54 -0
  288. package/package.json +9 -11
  289. package/clients/cli/lib/update-check.mjs +0 -83
  290. package/clients/cli/lib/update-check.test.mjs +0 -137
  291. package/clients/cli/update-hint-commands.test.mjs +0 -54
@@ -53,7 +53,7 @@ export const doc = {
53
53
  {
54
54
  type: 'search',
55
55
  description:
56
- 'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit` (domain, name, score, reason, description, follow-up command, and import path where relevant).',
56
+ 'The query echoed back, `matchCount` (how many candidates matched in total, before `limit`), plus a ranked SearchResultEntry[] bounded by `limit`: each has domain, name, score, reason, description, and follow-up command, plus `import` for components and hooks, `title` for docs, and `displayName` and `kind` for templates.',
57
57
  },
58
58
  ],
59
59
  throws: [
@@ -61,6 +61,10 @@ export const doc = {
61
61
  code: 'ERR_INVALID_ARGUMENT',
62
62
  when: 'the query is empty, --type is unknown, or --limit is not a positive integer',
63
63
  },
64
+ {
65
+ code: 'ERR_CORE_NOT_FOUND',
66
+ when: '@astryxdesign/core cannot be found from the cwd',
67
+ },
64
68
  ],
65
69
  examples: [
66
70
  {label: 'Find a component', code: "const r = await search('button');"},
@@ -66,7 +66,7 @@ import {
66
66
  import {loadIntegrationsSafely} from '../component/_adapter.mjs';
67
67
  import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
68
68
  import {discoverTemplates, extractComponents} from '../template/template.mjs';
69
- import {loadDocsCatalog, loadTopicDoc} from '../docs/_adapter.mjs';
69
+ import {loadDocsCatalog, lowerTopic} from '../docs/_adapter.mjs';
70
70
  import {AstryxError} from '../error.mjs';
71
71
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
72
72
  import {setResultCoverage} from './coverage.mjs';
@@ -732,16 +732,16 @@ async function gatherHooks(coreDir) {
732
732
  async function gatherDocs(cwd) {
733
733
  /** @type {Candidate[]} */
734
734
  const candidates = [];
735
- let entries;
735
+ let catalog;
736
736
  try {
737
- entries = (await loadDocsCatalog(cwd)).entries();
737
+ catalog = await loadDocsCatalog(cwd);
738
738
  } catch {
739
739
  return candidates;
740
740
  }
741
- for (const entry of entries) {
741
+ for (const entry of catalog.entries()) {
742
742
  let doc = null;
743
743
  try {
744
- doc = await loadTopicDoc(entry);
744
+ doc = (await lowerTopic(catalog, entry)).doc;
745
745
  } catch {
746
746
  // A topic that cannot be loaded is reported by the commands that own
747
747
  // integration issues; search just cannot index it.
@@ -884,7 +884,7 @@ function toResult(c, score, reason, matchedTerms, queryTerms) {
884
884
  * @param {string} [options.cwd]
885
885
  * @param {'component'|'hook'|'doc'|'template'} [options.type] - Restrict to one domain.
886
886
  * @param {number} [options.limit] - Max results (default 20).
887
- * @returns {Promise<{type: 'search', data: {query: string, matchCount: number, results: Array<object>}}>}
887
+ * @returns {Promise<import('./search.type.mjs').SearchResponse>}
888
888
  */
889
889
  export async function search(query, options = {}) {
890
890
  const {cwd = process.cwd(), type, limit = 20} = options;
@@ -921,7 +921,11 @@ export async function search(query, options = {}) {
921
921
 
922
922
  const coreDir = findCoreDir(cwd);
923
923
  if (!coreDir) {
924
- throw new AstryxError('Could not find @astryxdesign/core package');
924
+ throw new AstryxError(
925
+ 'Could not find @astryxdesign/core package',
926
+ undefined,
927
+ ERROR_CODES.ERR_CORE_NOT_FOUND,
928
+ );
925
929
  }
926
930
 
927
931
  // Gather candidates from each requested domain in parallel.
@@ -971,7 +975,10 @@ export async function search(query, options = {}) {
971
975
  data: {
972
976
  query: String(query).trim(),
973
977
  matchCount: scored.length,
974
- results: limited,
978
+ // toResult gives every domain its command and domain fields.
979
+ results: /** @type {import('./search.type.mjs').SearchResultEntry[]} */ (
980
+ limited
981
+ ),
975
982
  },
976
983
  };
977
984
  }
@@ -21,6 +21,7 @@
21
21
 
22
22
  import {describe, it, expect} from 'vitest';
23
23
  import * as fs from 'node:fs';
24
+ import * as os from 'node:os';
24
25
  import * as path from 'node:path';
25
26
  import {fileURLToPath} from 'node:url';
26
27
  import {
@@ -70,6 +71,28 @@ describe('search leaf — envelope + ranking', () => {
70
71
  }, SLOW);
71
72
  });
72
73
 
74
+ describe('search leaf — per-domain result fields', () => {
75
+ it('carries import for components and hooks, title for docs, displayName and kind for templates', async () => {
76
+ const r = await search('theme', {cwd, limit: 60});
77
+ expect(new Set(r.data.results.map(res => res.domain))).toEqual(
78
+ new Set(SEARCH_DOMAINS),
79
+ );
80
+ for (const res of r.data.results) {
81
+ expect(typeof res.command).toBe('string');
82
+ expect(typeof res.description).toBe('string');
83
+ if (res.domain === 'component' || res.domain === 'hook') {
84
+ expect(res.import).toMatch(/\S/);
85
+ } else if (res.domain === 'doc') {
86
+ expect(res.title).toMatch(/\S/);
87
+ expect(res.command).toBe(`astryx docs ${res.name}`);
88
+ } else {
89
+ expect(res.displayName).toMatch(/\S/);
90
+ expect(['page', 'block']).toContain(res.kind);
91
+ }
92
+ }
93
+ }, SLOW);
94
+ });
95
+
73
96
  describe('search leaf — matchCount is the total, not the cap', () => {
74
97
  it('reports every match while `results` stays bounded by the limit', async () => {
75
98
  // The regression: `matchCount` used to be `results.length`, so a query
@@ -160,6 +183,17 @@ describe('search leaf — error paths (pinned)', () => {
160
183
  search('button', {cwd, type: /** @type {any} */ ('bogus')}),
161
184
  ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
162
185
  }, SLOW);
186
+
187
+ it('throws ERR_CORE_NOT_FOUND when @astryxdesign/core cannot be found', async () => {
188
+ const empty = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-search-no-core-'));
189
+ try {
190
+ await expect(search('button', {cwd: empty})).rejects.toMatchObject({
191
+ code: 'ERR_CORE_NOT_FOUND',
192
+ });
193
+ } finally {
194
+ fs.rmSync(empty, {recursive: true, force: true});
195
+ }
196
+ }, SLOW);
163
197
  });
164
198
 
165
199
  describe('search leaf — limit validation (API matches the CLI contract)', () => {
@@ -51,7 +51,7 @@ export type SearchResultEntry = {
51
51
  kind?: "page" | "block" | undefined;
52
52
  };
53
53
  /**
54
- * xds --json search <query>
54
+ * astryx --json search <query>
55
55
  */
56
56
  export type SearchResponse = {
57
57
  type: "search";
@@ -28,7 +28,7 @@
28
28
  */
29
29
 
30
30
  /**
31
- * xds --json search <query>
31
+ * astryx --json search <query>
32
32
  * @typedef {object} SearchResponse
33
33
  * @property {'search'} type
34
34
  * @property {object} data
@@ -159,6 +159,24 @@ function resolveOwners(coreDir, loadedIntegrations, name, coreIssuesUrl) {
159
159
  return owners;
160
160
  }
161
161
 
162
+ /**
163
+ * `assertWithin`, with an escape reported as ERR_PATH_TRAVERSAL.
164
+ * @param {string} target
165
+ * @param {string} cwd
166
+ * @param {{allowAbsolute?: boolean, label: string}} options
167
+ * @returns {string}
168
+ */
169
+ function confineWrite(target, cwd, options) {
170
+ try {
171
+ return assertWithin(target, cwd, options);
172
+ } catch (err) {
173
+ if (err instanceof PathSafetyError) {
174
+ throw new AstryxError(err.message, [], ERROR_CODES.ERR_PATH_TRAVERSAL);
175
+ }
176
+ throw err;
177
+ }
178
+ }
179
+
162
180
  /** @param {string} file */
163
181
  function isExcludedFromCopy(file) {
164
182
  return (
@@ -243,23 +261,22 @@ export async function swizzleCopy(component, options = {}) {
243
261
 
244
262
  const componentDir = owner.sourceDir;
245
263
 
246
- // Path-safety: --output must resolve inside cwd.
247
- let outputBase;
248
- try {
249
- outputBase = assertWithin(output, cwd, {label: 'output directory'});
250
- } catch (err) {
251
- if (err instanceof PathSafetyError) {
252
- throw new AstryxError(err.message, [], ERROR_CODES.ERR_PATH_TRAVERSAL);
253
- }
254
- throw err;
255
- }
264
+ // Path-safety: every write target resolves inside cwd, not just --output. An
265
+ // existing component directory or file may be a symlink out of cwd.
266
+ const outputBase = confineWrite(output, cwd, {label: 'output directory'});
256
267
  const outputDir = path.join(outputBase, dirName);
257
268
 
258
- // Pre-flight overwrite check before any mkdir/writeFile.
269
+ // Pre-flight path and overwrite checks before any mkdir/writeFile.
259
270
  const sourceFiles = fs.readdirSync(componentDir).filter(file => {
260
271
  if (isExcludedFromCopy(file)) return false;
261
272
  return fs.statSync(path.join(componentDir, file)).isFile();
262
273
  });
274
+ for (const file of sourceFiles) {
275
+ confineWrite(path.join(outputDir, file), cwd, {
276
+ allowAbsolute: true,
277
+ label: 'output file',
278
+ });
279
+ }
263
280
  const existingFiles = sourceFiles.filter(f =>
264
281
  fs.existsSync(path.join(outputDir, f)),
265
282
  );
@@ -80,7 +80,7 @@ export const doc = {
80
80
  },
81
81
  {
82
82
  code: 'ERR_PATH_TRAVERSAL',
83
- when: 'the component name contains a path separator or traversal, or output resolves outside cwd',
83
+ when: 'the component name contains a path separator or traversal, output resolves outside cwd, or an existing output file or directory is a symlink that resolves outside cwd',
84
84
  },
85
85
  {
86
86
  code: 'ERR_UNKNOWN_COMPONENT',
@@ -2,7 +2,7 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * xds --json swizzle [--list]
5
+ * astryx --json swizzle [--list]
6
6
  */
7
7
  export type SwizzleListResponse = {
8
8
  type: "swizzle.list";
@@ -22,7 +22,7 @@ export type SwizzleFeedback = {
22
22
  ghCommand?: string | undefined;
23
23
  };
24
24
  /**
25
- * xds --json swizzle <component>
25
+ * astryx --json swizzle <component>
26
26
  */
27
27
  export type SwizzleCopyResponse = {
28
28
  type: "swizzle.copy";
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  /**
10
- * xds --json swizzle [--list]
10
+ * astryx --json swizzle [--list]
11
11
  *
12
12
  * @typedef {object} SwizzleListResponse
13
13
  * @property {'swizzle.list'} type
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  /**
26
- * xds --json swizzle <component>
26
+ * astryx --json swizzle <component>
27
27
  *
28
28
  * @typedef {object} SwizzleCopyResponse
29
29
  * @property {'swizzle.copy'} type
@@ -36,13 +36,22 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
36
36
  );
37
37
  }
38
38
 
39
- // Path-safety: resolve the user-supplied targetPath relative to cwd,
40
- // rejecting absolute paths and any traversal that escapes the project
41
- // root. This guard runs BEFORE any mkdir/copyFile so we never create
42
- // directories outside the root just to fail on the file write.
43
- let resolvedTarget;
39
+ // If targetPath looks like a file (e.g. `./foo.tsx`), write directly to
40
+ // it. Previously this path was treated as a directory and the file was
41
+ // written as `./foo.tsx/page.tsx`, which is wrong and surprising.
42
+ const fileTarget = isFilePathArg(targetPath)
43
+ ? targetPath
44
+ : path.join(
45
+ targetPath,
46
+ match.type === 'block' ? path.basename(match.filePath) : 'page.tsx',
47
+ );
48
+
49
+ // Path-safety: the guard sees the file that will be written, not only its
50
+ // directory — a symlink at that name would otherwise carry the write
51
+ // outside the project root. Runs BEFORE any mkdir/write.
52
+ let outputFilePath;
44
53
  try {
45
- resolvedTarget = assertWithin(targetPath, cwd, {
54
+ outputFilePath = assertWithin(fileTarget, cwd, {
46
55
  label: 'template target path',
47
56
  });
48
57
  } catch (err) {
@@ -55,23 +64,8 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
55
64
  }
56
65
  throw err;
57
66
  }
58
-
59
- // If targetPath looks like a file (e.g. `./foo.tsx`), write directly to
60
- // it. Previously this path was treated as a directory and the file was
61
- // written as `./foo.tsx/page.tsx`, which is wrong and surprising.
62
- let outputDir;
63
- let outputFileName;
64
- let outputFilePath;
65
- if (isFilePathArg(targetPath)) {
66
- outputDir = path.dirname(resolvedTarget);
67
- outputFileName = path.basename(resolvedTarget);
68
- outputFilePath = resolvedTarget;
69
- } else {
70
- outputDir = resolvedTarget;
71
- outputFileName =
72
- match.type === 'block' ? path.basename(match.filePath) : 'page.tsx';
73
- outputFilePath = path.join(outputDir, outputFileName);
74
- }
67
+ const outputDir = path.dirname(outputFilePath);
68
+ const outputFileName = path.basename(outputFilePath);
75
69
 
76
70
  // Refuse to clobber an existing file unless the caller opts in. The CLI has
77
71
  // its own pre-flight collision message, but the API is a public surface
@@ -48,4 +48,21 @@ describe('template.copy — overwrite + path safety', () => {
48
48
  ).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
49
49
  expect(fs.existsSync(path.join(dir, '..', 'escape.tsx'))).toBe(false);
50
50
  }, SLOW);
51
+
52
+ it('rejects a directory target whose page.tsx is a symlink leading outside cwd', async () => {
53
+ const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-copy-outside-'));
54
+ try {
55
+ const victim = path.join(outside, 'victim.tsx');
56
+ fs.writeFileSync(victim, 'OUTSIDE');
57
+ fs.mkdirSync(path.join(dir, 'dest'));
58
+ fs.symlinkSync(victim, path.join(dir, 'dest', 'page.tsx'));
59
+
60
+ await expect(
61
+ template('blank', {targetPath: './dest', overwrite: true, cwd: dir}),
62
+ ).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
63
+ expect(fs.readFileSync(victim, 'utf-8')).toBe('OUTSIDE');
64
+ } finally {
65
+ fs.rmSync(outside, {recursive: true, force: true});
66
+ }
67
+ }, SLOW);
51
68
  });
@@ -75,7 +75,8 @@ export const doc = {
75
75
  name: 'options.targetPath',
76
76
  type: 'string',
77
77
  description:
78
- 'Destination (relative to cwd) to scaffold the template into. Its presence switches a named lookup into a copy.',
78
+ 'Destination (relative to cwd) to scaffold the template into. Its presence switches a named lookup into a copy. ' +
79
+ 'A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is the file to write; any other path is a directory, which receives page.tsx for a page template or the block\'s own file name for a block.',
79
80
  },
80
81
  {
81
82
  name: 'options.overwrite',
@@ -2,7 +2,7 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * xds --json template [--list]
5
+ * astryx --json template [--list]
6
6
  */
7
7
  export type TemplateListResponse = {
8
8
  type: "template.list";
@@ -53,7 +53,7 @@ export type TemplateListEntry = {
53
53
  scaffold?: boolean | undefined;
54
54
  };
55
55
  /**
56
- * xds --json template <name>
56
+ * astryx --json template <name>
57
57
  */
58
58
  export type TemplateShowResponse = {
59
59
  type: "template.show";
@@ -66,7 +66,7 @@ export type TemplateShowResponse = {
66
66
  };
67
67
  };
68
68
  /**
69
- * xds --json template <name> --skeleton
69
+ * astryx --json template <name> --skeleton
70
70
  */
71
71
  export type TemplateSkeletonResponse = {
72
72
  type: "template.skeleton";
@@ -78,7 +78,7 @@ export type TemplateSkeletonResponse = {
78
78
  };
79
79
  };
80
80
  /**
81
- * xds --json template <name> [path]
81
+ * astryx --json template <name> [path]
82
82
  */
83
83
  export type TemplateCopyResponse = {
84
84
  type: "template.copy";
@@ -90,7 +90,7 @@ export type TemplateCopyResponse = {
90
90
  };
91
91
  };
92
92
  /**
93
- * xds --json template --cdn [path]
93
+ * astryx --json template --cdn [path]
94
94
  * `written: false` with `reason: 'exists'` is a success: the command is safe to
95
95
  * re-run, and an edited page is the consumer's file to keep. `version` is the
96
96
  * Astryx version every CDN URL in the file was pinned to.
@@ -6,18 +6,18 @@
6
6
  *
7
7
  * Each template is exactly two files: page.tsx (code) + template.doc.mjs (metadata).
8
8
  *
9
- * Invocation -> type discriminator
9
+ * Invocation -> type discriminator
10
10
  * ------------------------------------------------------------------
11
- * xds --json template [--list] -> template.list
12
- * xds --json template <name> -> template.show
13
- * xds --json template <name> --skeleton -> template.skeleton
14
- * xds --json template <name> [path] -> template.copy
15
- * xds --json template --cdn [path] -> template.cdn
16
- * (unknown template) -> CLIError
11
+ * astryx --json template [--list] -> template.list
12
+ * astryx --json template <name> -> template.show
13
+ * astryx --json template <name> --skeleton -> template.skeleton
14
+ * astryx --json template <name> [path] -> template.copy
15
+ * astryx --json template --cdn [path] -> template.cdn
16
+ * (unknown template) -> CLIError
17
17
  */
18
18
 
19
19
  /**
20
- * xds --json template [--list]
20
+ * astryx --json template [--list]
21
21
  * @typedef {object} TemplateListResponse
22
22
  * @property {'template.list'} type
23
23
  * @property {TemplateListEntry[]} data
@@ -43,7 +43,7 @@
43
43
  */
44
44
 
45
45
  /**
46
- * xds --json template <name>
46
+ * astryx --json template <name>
47
47
  * @typedef {object} TemplateShowResponse
48
48
  * @property {'template.show'} type
49
49
  * @property {object} data
@@ -55,7 +55,7 @@
55
55
  */
56
56
 
57
57
  /**
58
- * xds --json template <name> --skeleton
58
+ * astryx --json template <name> --skeleton
59
59
  * @typedef {object} TemplateSkeletonResponse
60
60
  * @property {'template.skeleton'} type
61
61
  * @property {object} data
@@ -66,7 +66,7 @@
66
66
  */
67
67
 
68
68
  /**
69
- * xds --json template <name> [path]
69
+ * astryx --json template <name> [path]
70
70
  * @typedef {object} TemplateCopyResponse
71
71
  * @property {'template.copy'} type
72
72
  * @property {object} data
@@ -77,7 +77,7 @@
77
77
  */
78
78
 
79
79
  /**
80
- * xds --json template --cdn [path]
80
+ * astryx --json template --cdn [path]
81
81
  * `written: false` with `reason: 'exists'` is a success: the command is safe to
82
82
  * re-run, and an edited page is the consumer's file to keep. `version` is the
83
83
  * Astryx version every CDN URL in the file was pinned to.
@@ -0,0 +1,91 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
4
+ import * as fs from 'node:fs';
5
+ import * as os from 'node:os';
6
+ import * as path from 'node:path';
7
+ import {themeAdd} from './add.mjs';
8
+
9
+ const HEADER = '// Copyright (c) Meta Platforms, Inc. and affiliates.\n\n';
10
+
11
+ let tmpDir;
12
+
13
+ /** Every byte value, so any lossy text decoding shows up as a changed file. */
14
+ const FONT_BYTES = Buffer.concat([
15
+ Buffer.from('wOF2'),
16
+ Buffer.from(Array.from({length: 256}, (_, byte) => byte)),
17
+ ]);
18
+
19
+ beforeEach(() => {
20
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-themeadd-binary-'));
21
+ fs.writeFileSync(
22
+ path.join(tmpDir, 'package.json'),
23
+ JSON.stringify({
24
+ name: 'consumer',
25
+ dependencies: {'@acme/themes': '^1.0.0'},
26
+ }),
27
+ );
28
+ const packageDir = path.join(tmpDir, 'node_modules', '@acme', 'themes');
29
+ const themeDir = path.join(packageDir, 'themes', 'ocean');
30
+ fs.mkdirSync(path.join(themeDir, 'fonts'), {recursive: true});
31
+ fs.writeFileSync(
32
+ path.join(packageDir, 'package.json'),
33
+ JSON.stringify({name: '@acme/themes', version: '1.0.0'}),
34
+ );
35
+ fs.writeFileSync(
36
+ path.join(packageDir, 'astryx.integration.mjs'),
37
+ "export default {themes: './themes'};\n",
38
+ );
39
+ fs.writeFileSync(
40
+ path.join(packageDir, 'themes', 'manifest.json'),
41
+ JSON.stringify({
42
+ version: 1,
43
+ themes: [
44
+ {
45
+ slug: 'ocean',
46
+ displayName: 'Ocean',
47
+ description: 'Integration theme that ships a font.',
48
+ maintained: true,
49
+ entry: 'oceanTheme.ts',
50
+ exportName: 'oceanTheme',
51
+ files: ['oceanTheme.ts', 'fonts/ocean.woff2'],
52
+ },
53
+ ],
54
+ }),
55
+ );
56
+ fs.writeFileSync(
57
+ path.join(themeDir, 'oceanTheme.ts'),
58
+ `${HEADER}export const oceanTheme = {};\n`,
59
+ );
60
+ fs.writeFileSync(path.join(themeDir, 'fonts', 'ocean.woff2'), FONT_BYTES);
61
+ });
62
+
63
+ afterEach(() => {
64
+ fs.rmSync(tmpDir, {recursive: true, force: true});
65
+ });
66
+
67
+ describe('themeAdd copies every listed file', () => {
68
+ it('copies a binary file byte for byte', async () => {
69
+ const result = await themeAdd('ocean', {
70
+ cwd: tmpDir,
71
+ package: '@acme/themes',
72
+ });
73
+
74
+ expect(result.data.files).toEqual(['oceanTheme.ts', 'fonts/ocean.woff2']);
75
+ const copied = fs.readFileSync(
76
+ path.join(tmpDir, 'src', 'themes', 'ocean', 'fonts', 'ocean.woff2'),
77
+ );
78
+ expect(copied.equals(FONT_BYTES)).toBe(true);
79
+ });
80
+
81
+ it('still strips the repo header from a text source', async () => {
82
+ await themeAdd('ocean', {cwd: tmpDir, package: '@acme/themes'});
83
+
84
+ expect(
85
+ fs.readFileSync(
86
+ path.join(tmpDir, 'src', 'themes', 'ocean', 'oceanTheme.ts'),
87
+ 'utf-8',
88
+ ),
89
+ ).toBe('export const oceanTheme = {};\n');
90
+ });
91
+ });
@@ -26,6 +26,20 @@ function defaultTargetDir(slug) {
26
26
  return path.join('src', 'themes', slug);
27
27
  }
28
28
 
29
+ /**
30
+ * The bytes to write for one listed file. Only UTF-8 text loses our header;
31
+ * anything else (a font, an image) is copied verbatim, since decoding it would
32
+ * corrupt it.
33
+ * @param {Buffer} bytes
34
+ * @returns {Buffer | string}
35
+ */
36
+ function scaffoldContents(bytes) {
37
+ const text = bytes.toString('utf-8');
38
+ return Buffer.from(text, 'utf-8').equals(bytes)
39
+ ? stripCopyrightHeader(text)
40
+ : bytes;
41
+ }
42
+
29
43
  /**
30
44
  * Copy a bundled theme's files into the consumer's project (defaults to
31
45
  * `src/themes/<slug>/`). Writes are staged to temp files then renamed, rolling
@@ -135,8 +149,7 @@ export async function themeAdd(slug, options = {}) {
135
149
  });
136
150
  fs.mkdirSync(path.dirname(dest), {recursive: true});
137
151
  const tmp = `${dest}.${process.pid}.tmp`;
138
- const contents = stripCopyrightHeader(fs.readFileSync(w.src, 'utf-8'));
139
- fs.writeFileSync(tmp, contents);
152
+ fs.writeFileSync(tmp, scaffoldContents(fs.readFileSync(w.src)));
140
153
  staged.push({tmp, dest});
141
154
  }
142
155
  for (const s of staged) {