@astryxdesign/cli 0.6.3-canary.dea6813 → 0.6.3-canary.e7819e0

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 (176) hide show
  1. package/README.md +18 -32
  2. package/api/build/build.doc.mjs +3 -3
  3. package/api/build/build.test.mjs +3 -14
  4. package/api/build/build.type.d.mts +1 -35
  5. package/api/build/build.type.mjs +3 -24
  6. package/api/build/help/help.d.mts +5 -8
  7. package/api/build/help/help.mjs +6 -56
  8. package/api/component/component.doc.mjs +2 -11
  9. package/api/component/component.mjs +0 -29
  10. package/api/component/component.test.mjs +0 -38
  11. package/api/component/component.type.d.mts +1 -11
  12. package/api/component/component.type.mjs +1 -8
  13. package/api/discover/discover.doc.mjs +1 -1
  14. package/api/gap-report/gap-report.doc.mjs +4 -7
  15. package/api/init/init.doc.mjs +0 -4
  16. package/api/init/init.test.mjs +1 -41
  17. package/api/init/remove/remove.mjs +1 -1
  18. package/api/init/run/run.mjs +10 -20
  19. package/api/integration/add-contribution.mjs +0 -11
  20. package/api/integration/add-contribution.test.mjs +0 -80
  21. package/api/integration/integrationAdd.doc.mjs +4 -7
  22. package/api/integration/integrationAddComponent.doc.mjs +1 -1
  23. package/api/integration/validate-integration.mjs +0 -2
  24. package/api/integration/validateIntegration.doc.mjs +1 -1
  25. package/api/json/parseResponse.doc.mjs +2 -2
  26. package/api/layout/expand/expand.mjs +5 -7
  27. package/api/layout/grammar/grammar.mjs +1 -2
  28. package/api/layout/layoutExpand.doc.mjs +1 -1
  29. package/api/search/search.d.mts +9 -2
  30. package/api/search/search.doc.mjs +1 -5
  31. package/api/search/search.mjs +3 -10
  32. package/api/search/search.test.mjs +0 -34
  33. package/api/swizzle/copy/copy.mjs +11 -28
  34. package/api/swizzle/swizzle.doc.mjs +1 -1
  35. package/api/template/copy/copy.mjs +23 -17
  36. package/api/template/copy/copy.test.mjs +0 -17
  37. package/api/template/template.doc.mjs +1 -2
  38. package/api/theme/add/add.mjs +3 -20
  39. package/api/theme/build/build.mjs +37 -114
  40. package/api/theme/build/build.public-component-vars.test.mjs +1 -1
  41. package/api/theme/build/font-warning.mjs +3 -3
  42. package/api/theme/build/font-warning.test.mjs +2 -5
  43. package/api/theme/palette/generate/generate.mjs +2 -7
  44. package/api/theme/palette/generate/generate.test.mjs +0 -96
  45. package/api/theme/palette/generate/generator.mjs +1 -8
  46. package/api/theme/palette/generate/generator.test.mjs +0 -10
  47. package/api/theme/template/template.mjs +2 -11
  48. package/api/theme/template/template.test.mjs +0 -15
  49. package/api/theme/themeBuild.doc.mjs +4 -7
  50. package/api/theme/themeTemplate.doc.mjs +1 -4
  51. package/api/upgrade/_adapter.mjs +4 -27
  52. package/api/upgrade/list/list.mjs +1 -2
  53. package/api/upgrade/status/status.mjs +2 -2
  54. package/api/upgrade/upgrade.doc.mjs +1 -2
  55. package/api/upgrade/upgrade.type.d.mts +0 -4
  56. package/api/upgrade/upgrade.type.mjs +0 -1
  57. package/assets/codemods/term-log.mjs +8 -32
  58. package/assets/codemods/term-log.test.mjs +1 -19
  59. package/assets/codemods/transforms/v0.6.0/__tests__/next-codemods.test.mjs +0 -47
  60. package/assets/codemods/transforms/v0.6.0/rename-resizable-pixel-bounds.mjs +10 -57
  61. package/authoring/config/config.doc.mjs +1 -1
  62. package/authoring/config/type.ts +3 -15
  63. package/clients/cli/commands/blog.mjs +8 -23
  64. package/clients/cli/commands/blog.test.mjs +1 -42
  65. package/clients/cli/commands/build-theme.mjs +5 -5
  66. package/clients/cli/commands/build-theme.path-safety.test.mjs +1 -86
  67. package/clients/cli/commands/build-theme.variants.test.mjs +0 -76
  68. package/clients/cli/commands/build.doc.mjs +1 -4
  69. package/clients/cli/commands/build.mjs +47 -32
  70. package/clients/cli/commands/component/index.mjs +7 -2
  71. package/clients/cli/commands/component-package.test.mjs +0 -18
  72. package/clients/cli/commands/component-resolution.test.mjs +0 -21
  73. package/clients/cli/commands/component.test.mjs +0 -19
  74. package/clients/cli/commands/detail-levels.test.mjs +2 -2
  75. package/clients/cli/commands/discover.broken-integration.test.mjs +0 -48
  76. package/clients/cli/commands/discover.doc.mjs +2 -4
  77. package/clients/cli/commands/discover.mjs +3 -3
  78. package/clients/cli/commands/doctor.mjs +16 -6
  79. package/clients/cli/commands/doctor.test.mjs +0 -42
  80. package/clients/cli/commands/gap-report.doc.mjs +5 -16
  81. package/clients/cli/commands/gap-report.test.mjs +0 -72
  82. package/clients/cli/commands/hook/index.mjs +17 -7
  83. package/clients/cli/commands/init.doc.mjs +8 -19
  84. package/clients/cli/commands/integration-add.doc.mjs +5 -21
  85. package/clients/cli/commands/interactive-guard.test.mjs +24 -101
  86. package/clients/cli/commands/json-contract.test.mjs +0 -33
  87. package/clients/cli/commands/layout-check.doc.mjs +3 -14
  88. package/clients/cli/commands/layout-expand.doc.mjs +4 -21
  89. package/clients/cli/commands/layout.doc.mjs +2 -2
  90. package/clients/cli/commands/layout.mjs +9 -21
  91. package/clients/cli/commands/search.doc.mjs +3 -6
  92. package/clients/cli/commands/search.mjs +7 -17
  93. package/clients/cli/commands/search.test.mjs +0 -75
  94. package/clients/cli/commands/swizzle.doc.mjs +1 -2
  95. package/clients/cli/commands/swizzle.path-safety.test.mjs +0 -42
  96. package/clients/cli/commands/template.doc.mjs +6 -28
  97. package/clients/cli/commands/theme-add.doc.mjs +1 -2
  98. package/clients/cli/commands/theme-build.doc.mjs +6 -7
  99. package/clients/cli/commands/theme-palette-generate.test.mjs +0 -19
  100. package/clients/cli/commands/theme-template.behavior.test.mjs +0 -12
  101. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  102. package/clients/cli/commands/upgrade.doc.mjs +6 -17
  103. package/clients/cli/index.mjs +30 -13
  104. package/clients/cli/lib/cli-error.test.mjs +0 -7
  105. package/clients/cli/lib/component-format.mjs +9 -9
  106. package/clients/cli/lib/component-format.test.mjs +1 -1
  107. package/clients/cli/lib/define-command.mjs +6 -32
  108. package/clients/cli/lib/hook-format.mjs +5 -5
  109. package/clients/cli/lib/json-shim.mjs +2 -38
  110. package/clients/cli/lib/json-shim.test.mjs +0 -83
  111. package/clients/cli/lib/manifest.d.ts +0 -2
  112. package/clients/cli/lib/manifest.mjs +0 -22
  113. package/clients/cli/lib/manifest.test.mjs +0 -17
  114. package/clients/cli/lib/update-check.mjs +83 -0
  115. package/clients/cli/lib/update-check.test.mjs +137 -0
  116. package/clients/cli/update-hint-commands.test.mjs +54 -0
  117. package/foundation/agent-docs/agent-docs.d.mts +0 -4
  118. package/foundation/agent-docs/agent-docs.mjs +3 -69
  119. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +4 -266
  120. package/foundation/config/integration-debug.test.mjs +3 -28
  121. package/foundation/config/project.mjs +9 -123
  122. package/foundation/config/project.test.mjs +0 -126
  123. package/foundation/discovery/template-adapter.d.mts +5 -14
  124. package/foundation/discovery/template-adapter.mjs +25 -292
  125. package/foundation/fs/module-loader.d.mts +0 -1
  126. package/foundation/fs/module-loader.mjs +1 -50
  127. package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +94 -129
  128. package/foundation/integrations/autolink.mjs +1 -6
  129. package/foundation/response/base.d.ts +4 -8
  130. package/foundation/response/error-codes.doc.mjs +2 -1
  131. package/foundation/response/error-codes.mjs +1 -1
  132. package/foundation/response/error-codes.test.mjs +0 -83
  133. package/foundation/response/json-contract.test.mjs +0 -11
  134. package/foundation/response/json.d.mts +2 -4
  135. package/foundation/response/json.mjs +10 -8
  136. package/foundation/response/response-types.doc.mjs +3 -3
  137. package/foundation/xle/expand.d.mts +0 -2
  138. package/foundation/xle/expand.mjs +2 -3
  139. package/package.json +9 -9
  140. package/api/integration/add-contribution.component-names.test.mjs +0 -120
  141. package/api/json/envelope-types.test.mjs +0 -76
  142. package/api/layout/expand/expand.path-safety.test.mjs +0 -53
  143. package/api/search/search-return-type.test.mjs +0 -54
  144. package/api/theme/add/add.binary.test.mjs +0 -91
  145. package/api/theme/add/add.staging.test.mjs +0 -66
  146. package/api/theme/build/build.receipt-doc.test.mjs +0 -111
  147. package/api/upgrade/list/list.test.mjs +0 -73
  148. package/authoring/config/debug-composition.test.mjs +0 -92
  149. package/clients/cli/command-load-failure.test.mjs +0 -83
  150. package/clients/cli/commands/build-theme.ascii-output.test.mjs +0 -161
  151. package/clients/cli/commands/build-theme.flag-docs.test.mjs +0 -110
  152. package/clients/cli/commands/build.exit-codes-doc.test.mjs +0 -50
  153. package/clients/cli/commands/build.playbook.test.mjs +0 -75
  154. package/clients/cli/commands/build.text-fields.test.mjs +0 -40
  155. package/clients/cli/commands/discover.components-flag.test.mjs +0 -97
  156. package/clients/cli/commands/discover.text-projection.test.mjs +0 -103
  157. package/clients/cli/commands/doctor-integration.package-json.test.mjs +0 -53
  158. package/clients/cli/commands/hook.text-projection.test.mjs +0 -45
  159. package/clients/cli/commands/init.flag-help.test.mjs +0 -153
  160. package/clients/cli/commands/integration-add.controls.test.mjs +0 -132
  161. package/clients/cli/commands/layout.path-help.test.mjs +0 -33
  162. package/clients/cli/commands/layout.stdin-cap.test.mjs +0 -47
  163. package/clients/cli/commands/layout.text-fields.test.mjs +0 -39
  164. package/clients/cli/commands/no-prompt-wording.test.mjs +0 -94
  165. package/clients/cli/commands/template.flag-help.test.mjs +0 -117
  166. package/clients/cli/commands/template.path-help.test.mjs +0 -40
  167. package/clients/cli/commands/upgrade.ascii-output.test.mjs +0 -87
  168. package/clients/cli/commands/upgrade.flag-help.test.mjs +0 -188
  169. package/clients/cli/commands/upgrade.hook-output.test.mjs +0 -88
  170. package/clients/cli/latest-version-env.test.mjs +0 -50
  171. package/clients/cli/lib/doc-text-ascii.test.mjs +0 -82
  172. package/clients/cli/lib/exit-codes.test.mjs +0 -97
  173. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +0 -248
  174. package/foundation/discovery/template-adapter.integration-isolation.test.mjs +0 -94
  175. package/foundation/fs/module-loader.stdout.test.mjs +0 -332
  176. package/foundation/xle/expand.test.mjs +0 -54
@@ -230,40 +230,13 @@ describe('init() — logger', () => {
230
230
  errSpy.mockRestore();
231
231
  }
232
232
  const text = lines.join('\n');
233
- expect(text).toContain('[ok] AI agent docs installed -> AGENTS.md');
233
+ expect(text).toContain('✓ AI agent docs installed → AGENTS.md');
234
234
  expect(text).toContain(' Next steps:');
235
235
  // The exact next-steps block the CLI prints comes from getNextSteps().
236
236
  expect(text).toContain(getNextSteps('npx astryx')[2].slice(0, 20));
237
237
  });
238
238
  });
239
239
 
240
- describe('init() — ASCII output', () => {
241
- it('prints only ASCII on the default, all-features, re-run, template, and remove paths', async () => {
242
- /** @type {string[]} */
243
- const lines = [];
244
- const logSpy = vi.spyOn(console, 'log').mockImplementation((...a) => lines.push(a.join(' ')));
245
- const errSpy = vi.spyOn(console, 'error').mockImplementation((...a) => lines.push(a.join(' ')));
246
- const empty = fs.mkdtempSync(path.join(process.cwd(), '.astryx-init-remove-'));
247
- logger.setSilent(false);
248
- try {
249
- await init({}, {cwd: tmpDir});
250
- await init({all: true}, {cwd: tmpDir});
251
- await init({all: true}, {cwd: tmpDir});
252
- await init({features: 'template', templateName: 'blank'}, {cwd: tmpDir});
253
- await init({removeAgents: true}, {cwd: tmpDir});
254
- await init({removeAgents: true}, {cwd: empty});
255
- } finally {
256
- logger.setSilent(true);
257
- logSpy.mockRestore();
258
- errSpy.mockRestore();
259
- fs.rmSync(empty, {recursive: true, force: true});
260
- }
261
- expect(lines.length).toBeGreaterThan(0);
262
- expect(lines.some(line => line.startsWith('[ok] Removed'))).toBe(true);
263
- expect(lines.filter(line => /[\u0080-\uFFFF]/.test(line))).toEqual([]);
264
- });
265
- });
266
-
267
240
  describe('init() — write-path safety', () => {
268
241
  it('template scaffold refuses to clobber an existing page.tsx', async () => {
269
242
  const dest = path.join(tmpDir, 'src', 'pages', 'blank');
@@ -287,17 +260,4 @@ describe('init() — write-path safety', () => {
287
260
  init({features: 'template', templateName: '../../etc/evil'}, {cwd: tmpDir}),
288
261
  ).rejects.toMatchObject({code: ERROR_CODES.ERR_UNKNOWN_TEMPLATE});
289
262
  });
290
-
291
- it('refuses a template write that a symlinked src would carry outside cwd (ERR_PATH_TRAVERSAL)', async () => {
292
- const outside = fs.mkdtempSync(path.join(process.cwd(), '.astryx-init-outside-'));
293
- try {
294
- fs.symlinkSync(outside, path.join(tmpDir, 'src'), 'dir');
295
- await expect(
296
- init({features: 'template', templateName: 'blank'}, {cwd: tmpDir}),
297
- ).rejects.toMatchObject({code: ERROR_CODES.ERR_PATH_TRAVERSAL});
298
- expect(fs.readdirSync(outside)).toEqual([]);
299
- } finally {
300
- fs.rmSync(outside, {recursive: true, force: true});
301
- }
302
- });
303
263
  });
@@ -24,6 +24,6 @@ import {logger} from '../../logger.mjs';
24
24
  */
25
25
  export async function remove({cwd = process.cwd()} = {}) {
26
26
  removeAgentDocs(cwd);
27
- logger.log('[ok] AI agent docs removed.');
27
+ logger.log('✓ AI agent docs removed.');
28
28
  return {type: 'init.remove', data: {removed: true}};
29
29
  }
@@ -17,7 +17,7 @@
17
17
  import * as path from 'node:path';
18
18
  import * as fs from 'node:fs';
19
19
  import {CLI_ROOT} from '../../../foundation/fs/paths.mjs';
20
- import {PathSafetyError, assertWithin} from '../../../foundation/fs/path-safety.mjs';
20
+ import {PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
21
21
  import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
22
22
  import {
23
23
  installAgentDocs,
@@ -98,7 +98,7 @@ async function applyAgents(cwd, options, invocation, data) {
98
98
  renderedBlock,
99
99
  });
100
100
  data.docsWritten = written;
101
- logger.log(`[ok] AI agent docs installed -> ${written.join(', ')}`);
101
+ logger.log(`✓ AI agent docs installed → ${written.join(', ')}`);
102
102
  } catch (err) {
103
103
  // PathSafetyError carries a precise, user-actionable message — surface it
104
104
  // (and flag exit 1) instead of the generic "could not install" warning so
@@ -132,8 +132,8 @@ function applyTheme(cwd, invocation, data) {
132
132
  data.themeTemplatePath = didWrite ? written : null;
133
133
  logger.log(
134
134
  didWrite
135
- ? `[ok] Theme template written -> ${written}`
136
- : `- ${written} already exists - left as is.`,
135
+ ? `✓ Theme template written → ${written}`
136
+ : `• ${written} already exists — left as is.`,
137
137
  );
138
138
  } catch {
139
139
  // Soft failure, like agent docs: the guidance below is still useful.
@@ -166,16 +166,16 @@ function applyTemplate(cwd, {templateName}, invocation, data) {
166
166
  // Point agents at the build workflow rather than dumping page-template
167
167
  // names — `build` surfaces pages AND blocks AND components for an idea,
168
168
  // and `build` with no args is the full how-to-build playbook.
169
- logger.log('[ok] To build UI, use these commands:');
169
+ logger.log('✓ To build UI, use these commands:');
170
170
  logger.log('');
171
171
  logger.log(
172
- ` ${invocation} build "<what you're building>" build a page - kit: closest template + blocks + components`,
172
+ ` ${invocation} build "<what you're building>" build a page — kit: closest template + blocks + components`,
173
173
  );
174
174
  logger.log(
175
175
  ` ${invocation} build the how-to-build workflow (read this first)`,
176
176
  );
177
177
  logger.log(
178
- ` ${invocation} search <query> find anything - components, docs, templates, blocks`,
178
+ ` ${invocation} search <query> find anything — components, docs, templates, blocks`,
179
179
  );
180
180
  logger.log('');
181
181
  data.template = 'workflow';
@@ -190,19 +190,9 @@ function applyTemplate(cwd, {templateName}, invocation, data) {
190
190
  );
191
191
  }
192
192
 
193
- let destFile;
194
- try {
195
- destFile = assertWithin(path.join('src', 'pages', templateName, 'page.tsx'), cwd, {
196
- label: 'template output path',
197
- });
198
- } catch (err) {
199
- if (err instanceof PathSafetyError) {
200
- throw new AstryxError(err.message, undefined, ERROR_CODES.ERR_PATH_TRAVERSAL);
201
- }
202
- throw err;
203
- }
204
- const outputDir = path.dirname(destFile);
193
+ const outputDir = path.resolve(cwd, `./src/pages/${templateName}`);
205
194
  const srcPath = path.join(CLI_ROOT, 'assets', 'templates', 'pages', templateName, 'page.tsx');
195
+ const destFile = path.join(outputDir, 'page.tsx');
206
196
  // Don't clobber a user's existing page — same guard the peer template/copy and
207
197
  // theme/add write-leaves apply (init is a public API surface too).
208
198
  if (fs.existsSync(destFile)) {
@@ -216,7 +206,7 @@ function applyTemplate(cwd, {templateName}, invocation, data) {
216
206
  fs.mkdirSync(outputDir, {recursive: true});
217
207
  fs.copyFileSync(srcPath, destFile);
218
208
  const rel = path.relative(cwd, outputDir);
219
- logger.log(`[ok] Template created at ${rel}/page.tsx`);
209
+ logger.log(`✓ Template created at ${rel}/page.tsx`);
220
210
  data.template = 'created';
221
211
  data.templatePath = rel;
222
212
  }
@@ -35,7 +35,6 @@ import {
35
35
  } from '../../foundation/integrations/integrations.mjs';
36
36
  import {isValidSemver} from '../../foundation/env/semver.mjs';
37
37
  import {assertContributionVisible} from '../../foundation/integrations/contribution-inventory.mjs';
38
- import {findIntegrationComponentDoc} from '../../foundation/discovery/component-discovery.mjs';
39
38
  import {parseAgentDocsField} from '../../authoring/integration/schema.mjs';
40
39
  import {integrationAddTheme} from './add-theme.mjs';
41
40
  import {
@@ -249,16 +248,6 @@ async function addComponent(name, options) {
249
248
  ERROR_CODES.ERR_FILE_EXISTS,
250
249
  );
251
250
  }
252
- // Discovery keys components by doc stem anywhere under the root, so a second
253
- // doc with this name would shadow one of the two.
254
- const existingDoc = findIntegrationComponentDoc({components: root}, name);
255
- if (existingDoc != null) {
256
- throw new AstryxError(
257
- `Refusing to add component "${name}": ${projectPath(path.relative(packageDir, existingDoc))} already defines it.`,
258
- undefined,
259
- ERROR_CODES.ERR_FILE_EXISTS,
260
- );
261
- }
262
251
 
263
252
  const sourcePath = projectPath(path.relative(packageDir, sourceFile));
264
253
  const extensionlessPath = sourcePath.replace(/\.tsx?$/u, '');
@@ -731,83 +731,3 @@ describe('public dispatcher', () => {
731
731
  ).rejects.toThrow(/component, doc, template, codemod, agent-doc, or theme/);
732
732
  });
733
733
  });
734
-
735
- describe('dry-run receipts match the real write', () => {
736
- /** Package states each writer has to plan for. */
737
- const STATES = {
738
- 'no manifest': {pkg: {files: ['dist']}},
739
- 'an empty manifest': {pkg: {}, manifest: 'export default {};\n'},
740
- 'declared roots and an exports map': {
741
- pkg: {files: ['dist'], exports: {'.': './dist/index.js'}},
742
- manifest:
743
- "export default {\n components: './components',\n docs: './docs',\n templates: './templates',\n codemods: './codemods',\n themes: './themes',\n};\n",
744
- },
745
- };
746
- /** @type {Array<[any, string, Record<string, unknown>]>} */
747
- const KINDS = [
748
- ['component', 'AcmeWidget', {}],
749
- ['doc', 'deploying', {}],
750
- ['template', 'account-page', {}],
751
- ['template', 'account-card', {templateType: 'block'}],
752
- ['codemod', 'rename-widget', {to: '1.2.0'}],
753
- ['agent-doc', 'Run acme verify before finishing.', {}],
754
- ['theme', 'ocean', {}],
755
- ];
756
-
757
- /** Every file under the package, keyed by project path, with its bytes. */
758
- function snapshot() {
759
- /** @type {Record<string, string>} */
760
- const files = {};
761
- /** @param {string} dir */
762
- const walk = dir => {
763
- for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
764
- const full = path.join(dir, entry.name);
765
- if (entry.isDirectory()) walk(full);
766
- else {
767
- files[path.relative(tmpDir, full).split(path.sep).join('/')] =
768
- fs.readFileSync(full, 'base64');
769
- }
770
- }
771
- };
772
- walk(tmpDir);
773
- return files;
774
- }
775
-
776
- for (const [stateName, state] of Object.entries(STATES)) {
777
- for (const [kind, name, options] of KINDS) {
778
- it(`${kind} ${name} in a package with ${stateName}`, async () => {
779
- fs.writeFileSync(
780
- path.join(tmpDir, 'package.json'),
781
- `${JSON.stringify({name: '@acme/integration', version: '1.0.0', ...state.pkg}, null, 2)}\n`,
782
- );
783
- if (state.manifest != null) {
784
- fs.writeFileSync(
785
- path.join(tmpDir, 'astryx.integration.mjs'),
786
- state.manifest,
787
- );
788
- }
789
- const before = snapshot();
790
-
791
- const plan = await integrationAdd(kind, name, {
792
- cwd: tmpDir,
793
- dryRun: true,
794
- ...options,
795
- });
796
- expect(snapshot()).toEqual(before);
797
-
798
- const written = await integrationAdd(kind, name, {
799
- cwd: tmpDir,
800
- ...options,
801
- });
802
- const after = snapshot();
803
- const changed = Object.keys(after)
804
- .filter(file => after[file] !== before[file])
805
- .sort();
806
-
807
- expect(written.data.root).toEqual(plan.data.root);
808
- expect(written.data.files).toEqual(plan.data.files);
809
- expect([...written.data.files].sort()).toEqual(changed);
810
- });
811
- }
812
- }
813
- });
@@ -33,8 +33,7 @@ export const doc = {
33
33
  {
34
34
  name: 'name',
35
35
  type: 'string',
36
- description:
37
- 'Contribution name: PascalCase for component, lowercase kebab-case for template, codemod, and theme, letters, digits, _ and - for doc, or the literal agent-doc line.',
36
+ description: 'Contribution name, or the literal agent-doc line.',
38
37
  required: true,
39
38
  },
40
39
  {
@@ -57,19 +56,17 @@ export const doc = {
57
56
  {
58
57
  name: 'options.replaces',
59
58
  type: 'string',
60
- description:
61
- 'Existing topic to replace. Only valid for doc, and not with options.extends.',
59
+ description: 'Existing topic to replace. Only valid for doc.',
62
60
  },
63
61
  {
64
62
  name: 'options.extends',
65
63
  type: 'string',
66
- description:
67
- 'Existing topic to extend. Only valid for doc, and not with options.replaces.',
64
+ description: 'Existing topic to extend. Only valid for doc.',
68
65
  },
69
66
  {
70
67
  name: 'options.to',
71
68
  type: 'string',
72
- description: 'Exact target semver (e.g. 1.2.0). Required for codemod and only valid there.',
69
+ description: 'Exact target semver. Required for codemod.',
73
70
  },
74
71
  ],
75
72
  returns: [
@@ -8,7 +8,7 @@ export const doc = {
8
8
  displayName: 'integrationAddComponent()',
9
9
  summary: 'Add a complete component contribution.',
10
10
  description:
11
- 'Creates the same-stem component source and metadata pair, declares the components root on first use, preserves existing package allowlists, and publishes an exact source subpath when the package already has an exports map. Refuses with ERR_FILE_EXISTS when a component doc anywhere under the components root already uses the name.',
11
+ 'Creates the same-stem component source and metadata pair, declares the components root on first use, preserves existing package allowlists, and publishes an exact source subpath when the package already has an exports map.',
12
12
  importPath: '@astryxdesign/cli/api',
13
13
  signature:
14
14
  'integrationAddComponent(name: string, options?: IntegrationAddComponentOptions): Promise<IntegrationAddResponse>',
@@ -400,10 +400,8 @@ export async function validateLocalIntegration(cwd = process.cwd()) {
400
400
  try {
401
401
  pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
402
402
  } catch (err) {
403
- // A null name means "no manifest here"; this package has one.
404
403
  return {
405
404
  found: true,
406
- name: '(local package)',
407
405
  manifestFile: manifests[0],
408
406
  issues: [
409
407
  error(
@@ -45,7 +45,7 @@ export const doc = {
45
45
  {
46
46
  type: 'integration.validate',
47
47
  description:
48
- 'The result envelope: `data.name` and `data.version` of the validated package (both null only when no local manifest is found; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',
48
+ 'The result envelope: `data.name` and `data.version` of the validated package (both null when no local manifest is found), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message}.',
49
49
  },
50
50
  ],
51
51
  examples: [
@@ -16,7 +16,7 @@ export const doc = {
16
16
  description:
17
17
  'The entry point for consuming the CLI as a subprocess. A JSON string is parsed; ' +
18
18
  'an already-parsed object is passed through unchanged, so it is safe to call on ' +
19
- 'either. It returns the structural { apiVersion, type, data, meta? } envelope without narrowing: ' +
19
+ 'either. It returns the structural { type, data, meta? } envelope without narrowing: ' +
20
20
  '`data` stays unknown until you discriminate on `type` (or use assertResponse).',
21
21
  importPath: '@astryxdesign/cli/json',
22
22
  signature: 'parseResponse(raw: unknown): any',
@@ -34,7 +34,7 @@ export const doc = {
34
34
  {
35
35
  type: 'any',
36
36
  description:
37
- 'The { apiVersion, type, data, meta? } envelope, or a CLIError envelope ({ apiVersion, error, code, suggestions? }). The published signature is intentionally untyped; narrow it by casting to the matching *Response type exported from @astryxdesign/cli/json.',
37
+ 'The { type, data, meta? } envelope, or a CLIError envelope. The published signature is intentionally untyped; narrow it by casting to the matching *Response type exported from @astryxdesign/cli/json.',
38
38
  },
39
39
  ],
40
40
  throws: [
@@ -120,20 +120,18 @@ export async function layoutExpand(expression, options = {}) {
120
120
 
121
121
  let written = null;
122
122
  if (targetPath) {
123
- // The guard sees the file that will be written, not only its directory:
124
- // a symlink at that name would otherwise carry the write outside the root.
125
- const fileTarget = isFilePathArg(targetPath)
126
- ? targetPath
127
- : path.join(targetPath, `${componentName}.tsx`);
128
- let filePath;
123
+ let resolved;
129
124
  try {
130
- filePath = assertWithin(fileTarget, cwd, {label: 'layout target path'});
125
+ resolved = assertWithin(targetPath, cwd, {label: 'layout target path'});
131
126
  } catch (err) {
132
127
  if (err instanceof PathSafetyError) {
133
128
  throw new AstryxError(err.message, undefined, ERROR_CODES.ERR_PATH_TRAVERSAL);
134
129
  }
135
130
  throw err;
136
131
  }
132
+ const filePath = isFilePathArg(targetPath)
133
+ ? resolved
134
+ : path.join(resolved, `${componentName}.tsx`);
137
135
  fs.mkdirSync(path.dirname(filePath), {recursive: true});
138
136
  fs.writeFileSync(filePath, result.code);
139
137
  written = path.relative(cwd, filePath);
@@ -10,7 +10,6 @@
10
10
  */
11
11
 
12
12
  import {buildRegistry} from '../../../foundation/xle/registry.mjs';
13
- import {MAX_REPEAT} from '../../../foundation/xle/expand.mjs';
14
13
 
15
14
  /**
16
15
  * `astryx layout grammar` — the agent cheatsheet, with the alias table
@@ -51,7 +50,7 @@ NODE ANATOMY Name#id.enum"payload"[attrs]{hint}*N > children
51
50
  .enum unique enum value of any prop: Bd.success Tx.lg B.primary
52
51
  "payload" primary text prop (label/title/heading) or text child: TI"Email" B"Save"
53
52
  {hint} kebab-case template/component reference (see TEMPLATE REFERENCING) — NEVER text
54
- *N / xN repeat, at most ${MAX_REPEAT} copies (use $ for the counter: Tk"item-$"*3)
53
+ *N / xN repeat (use $ for the counter: Tk"item-$"*3)
55
54
  trailing ! initial selection for scaffolded state: Tab"Overview"!
56
55
 
57
56
  ATTRS [...] (outline: bare tokens after the name, no brackets)
@@ -36,7 +36,7 @@ export const doc = {
36
36
  name: 'options.targetPath',
37
37
  type: 'string',
38
38
  description:
39
- 'Write the generated TSX here (validated to stay within cwd). A path that ends in .tsx, .ts, .jsx, .js, .mjs, .cjs, .css, .scss, .json, .md or .html is used as-is; any other path is a directory that gets <name>.tsx. An existing file is replaced. Omit to return the code without writing.',
39
+ 'Write the generated TSX here (validated to stay within cwd). A directory gets <name>.tsx; a file path is used as-is. Omit to return the code without writing.',
40
40
  },
41
41
  {
42
42
  name: 'options.form',
@@ -68,13 +68,20 @@ export function scoreCandidate(term: string, { name, keywords, weakKeywords, des
68
68
  * @param {string} [options.cwd]
69
69
  * @param {'component'|'hook'|'doc'|'template'} [options.type] - Restrict to one domain.
70
70
  * @param {number} [options.limit] - Max results (default 20).
71
- * @returns {Promise<import('./search.type.mjs').SearchResponse>}
71
+ * @returns {Promise<{type: 'search', data: {query: string, matchCount: number, results: Array<object>}}>}
72
72
  */
73
73
  export function search(query: string, options?: {
74
74
  cwd?: string | undefined;
75
75
  type?: "component" | "hook" | "doc" | "template" | undefined;
76
76
  limit?: number | undefined;
77
- }): Promise<import("./search.type.mjs").SearchResponse>;
77
+ }): Promise<{
78
+ type: "search";
79
+ data: {
80
+ query: string;
81
+ matchCount: number;
82
+ results: Array<object>;
83
+ };
84
+ }>;
78
85
  /** Valid domain filters for `--type`. */
79
86
  export const SEARCH_DOMAINS: string[];
80
87
  /**
@@ -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`: 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.',
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).',
57
57
  },
58
58
  ],
59
59
  throws: [
@@ -61,10 +61,6 @@ 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
- },
68
64
  ],
69
65
  examples: [
70
66
  {label: 'Find a component', code: "const r = await search('button');"},
@@ -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<import('./search.type.mjs').SearchResponse>}
887
+ * @returns {Promise<{type: 'search', data: {query: string, matchCount: number, results: Array<object>}}>}
888
888
  */
889
889
  export async function search(query, options = {}) {
890
890
  const {cwd = process.cwd(), type, limit = 20} = options;
@@ -921,11 +921,7 @@ export async function search(query, options = {}) {
921
921
 
922
922
  const coreDir = findCoreDir(cwd);
923
923
  if (!coreDir) {
924
- throw new AstryxError(
925
- 'Could not find @astryxdesign/core package',
926
- undefined,
927
- ERROR_CODES.ERR_CORE_NOT_FOUND,
928
- );
924
+ throw new AstryxError('Could not find @astryxdesign/core package');
929
925
  }
930
926
 
931
927
  // Gather candidates from each requested domain in parallel.
@@ -975,10 +971,7 @@ export async function search(query, options = {}) {
975
971
  data: {
976
972
  query: String(query).trim(),
977
973
  matchCount: scored.length,
978
- // toResult gives every domain its command and domain fields.
979
- results: /** @type {import('./search.type.mjs').SearchResultEntry[]} */ (
980
- limited
981
- ),
974
+ results: limited,
982
975
  },
983
976
  };
984
977
  }
@@ -21,7 +21,6 @@
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';
25
24
  import * as path from 'node:path';
26
25
  import {fileURLToPath} from 'node:url';
27
26
  import {
@@ -71,28 +70,6 @@ describe('search leaf — envelope + ranking', () => {
71
70
  }, SLOW);
72
71
  });
73
72
 
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
-
96
73
  describe('search leaf — matchCount is the total, not the cap', () => {
97
74
  it('reports every match while `results` stays bounded by the limit', async () => {
98
75
  // The regression: `matchCount` used to be `results.length`, so a query
@@ -183,17 +160,6 @@ describe('search leaf — error paths (pinned)', () => {
183
160
  search('button', {cwd, type: /** @type {any} */ ('bogus')}),
184
161
  ).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
185
162
  }, 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);
197
163
  });
198
164
 
199
165
  describe('search leaf — limit validation (API matches the CLI contract)', () => {
@@ -159,24 +159,6 @@ 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
-
180
162
  /** @param {string} file */
181
163
  function isExcludedFromCopy(file) {
182
164
  return (
@@ -261,22 +243,23 @@ export async function swizzleCopy(component, options = {}) {
261
243
 
262
244
  const componentDir = owner.sourceDir;
263
245
 
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'});
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
+ }
267
256
  const outputDir = path.join(outputBase, dirName);
268
257
 
269
- // Pre-flight path and overwrite checks before any mkdir/writeFile.
258
+ // Pre-flight overwrite check before any mkdir/writeFile.
270
259
  const sourceFiles = fs.readdirSync(componentDir).filter(file => {
271
260
  if (isExcludedFromCopy(file)) return false;
272
261
  return fs.statSync(path.join(componentDir, file)).isFile();
273
262
  });
274
- for (const file of sourceFiles) {
275
- confineWrite(path.join(outputDir, file), cwd, {
276
- allowAbsolute: true,
277
- label: 'output file',
278
- });
279
- }
280
263
  const existingFiles = sourceFiles.filter(f =>
281
264
  fs.existsSync(path.join(outputDir, f)),
282
265
  );
@@ -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, output resolves outside cwd, or an existing output file or directory is a symlink that resolves outside cwd',
83
+ when: 'the component name contains a path separator or traversal, or output resolves outside cwd',
84
84
  },
85
85
  {
86
86
  code: 'ERR_UNKNOWN_COMPONENT',
@@ -36,22 +36,13 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
36
36
  );
37
37
  }
38
38
 
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;
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;
53
44
  try {
54
- outputFilePath = assertWithin(fileTarget, cwd, {
45
+ resolvedTarget = assertWithin(targetPath, cwd, {
55
46
  label: 'template target path',
56
47
  });
57
48
  } catch (err) {
@@ -64,8 +55,23 @@ export function templateCopy(match, {targetPath, cwd, overwrite = false}) {
64
55
  }
65
56
  throw err;
66
57
  }
67
- const outputDir = path.dirname(outputFilePath);
68
- const outputFileName = path.basename(outputFilePath);
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
+ }
69
75
 
70
76
  // Refuse to clobber an existing file unless the caller opts in. The CLI has
71
77
  // its own pre-flight collision message, but the API is a public surface