@astryxdesign/cli 0.7.3 → 0.7.4-canary.b25f95e

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 (35) hide show
  1. package/README.md +5 -5
  2. package/api/discover/_adapter.mjs +22 -10
  3. package/api/discover/_catalog-view.d.mts +2 -0
  4. package/api/discover/_catalog-view.mjs +1 -0
  5. package/api/discover/_catalog-view.test.mjs +1 -0
  6. package/api/discover/detail/detail.mjs +1 -0
  7. package/api/discover/detail/detail.test.mjs +3 -0
  8. package/api/discover/detail/doc/doc.mjs +5 -1
  9. package/api/discover/detail/doc/doc.test.mjs +1 -0
  10. package/api/discover/detail/item/item.mjs +2 -0
  11. package/api/discover/detail/item/item.test.mjs +2 -0
  12. package/api/discover/discover.doc.mjs +4 -4
  13. package/api/discover/discover.type.d.mts +20 -0
  14. package/api/discover/discover.type.mjs +5 -0
  15. package/api/discover/list/list.test.mjs +2 -0
  16. package/api/discover/search/search.d.mts +3 -2
  17. package/api/discover/search/search.mjs +26 -7
  18. package/api/discover/search/search.test.mjs +67 -0
  19. package/api/integration/pack-check.mjs +6 -1
  20. package/api/integration/pack-check.test.mjs +14 -0
  21. package/api/theme/palette/generate/generate.d.mts +8 -0
  22. package/api/theme/palette/generate/generate.mjs +38 -11
  23. package/api/theme/palette/generate/generate.test.mjs +83 -4
  24. package/api/theme/palette/generate/generator.d.mts +6 -0
  25. package/api/theme/palette/generate/generator.mjs +6 -0
  26. package/api/theme/theme.type.d.mts +12 -1
  27. package/api/theme/theme.type.mjs +7 -1
  28. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  29. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +1 -1
  30. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +1 -1
  31. package/clients/cli/commands/discover.mjs +1 -1
  32. package/clients/cli/commands/discover.sources.test.mjs +6 -0
  33. package/foundation/response/response-types.doc.mjs +5 -5
  34. package/foundation/response/response-types.doc.test.mjs +29 -0
  35. package/package.json +9 -9
package/README.md CHANGED
@@ -489,10 +489,10 @@ Every response has a `type` discriminant. The full set is below (generated from
489
489
  | `docs.node` | One node of the docs tree, read by its route: its id, kind, package, title, summary, and breadcrumb, plus a namespace's slots with their children (one level down, each naming its package) or a typed doc's content, and links ({up, previous, next, related}: the commands that open its parent, its neighbors, and the docs it names). |
490
490
  | `blog.list` | The feed URL plus every post parsed from the RSS feed, each with slug, title, description, date, type, authors, link, and plaintext URL. |
491
491
  | `blog.detail` | One post's metadata plus the feed URL and the post's full plaintext body. |
492
- | `discover.list` | What the project has, the integrations it loads and the official packages it declares, official packages first (name, category, components, version, a list per other kind they add, and latest when a source knows it); meta.available lists what the project could add, the official packages first, each with the command that adds it, and meta.sources reports each source, the official list last; when it lists no integration it carries meta.configured to tell "nothing configured" from "nothing discovered". |
493
- | `discover.detail` | One package, for an @scope/name or @scope/name@version query: what the shown version adds, whether the project has it, and, when a source knows the package, its versions, latest release, and the command that adds it. |
494
- | `discover.detail.doc` | The validated ComponentDoc for one installed component, for an @scope/name/Component query. |
495
- | `discover.item` | One item that is not an installed component, for an @scope/name/<item> query: its kind, name, package, version, and whether the project has the package. |
492
+ | `discover.list` | What the project has, the integrations it loads and the official packages it declares, official packages first (package, the npm package and always equal to name; name, category, components, version, a list per other kind they add, and latest when a source knows it); meta.available lists what the project could add, the official packages first, each with its package and the command that adds it, and meta.sources reports each source, the official list last; when it lists no integration it carries meta.configured to tell "nothing configured" from "nothing discovered". |
493
+ | `discover.detail` | One package, for an @scope/name or @scope/name@version query: its package (the npm package the result is about), what the shown version adds, whether the project has it, and, when a source knows the package, its versions, latest release, and the command that adds it. |
494
+ | `discover.detail.doc` | The validated ComponentDoc for one installed component, for an @scope/name/Component query, plus package, the npm package that owns the component. |
495
+ | `discover.item` | One item that is not an installed component, for an @scope/name/<item> query: its kind, name, package, version, and whether the project has the package. The envelope's package names the same package. |
496
496
  | `discover.search` | The echoed query plus every matching item and package across all packages, each with its kind and whether the project has it, even when only one matches; total is set when --limit cut the list. |
497
497
  | `search` | The echoed query, `matchCount` (total matches, before `limit`), and results, a ranked SearchResultEntry[] bounded by `limit`: each {domain, name, package, score, reason, description, command} (package is the npm package that owns the result), plus import (components, hooks), title, parent (the command that opens the level above), and, for a hit on one section, section (docs), or displayName and kind (templates). When a search with no `type` could not obtain @astryxdesign/core, `meta.partial` is {skipped, reason}: the domains it skipped (component, hook, template) and why. |
498
498
  | `build.help` | The how-to-build-a-page playbook, emitted when no query is given: `playbook: true`, a title, the ordered steps (title, commands, optional returns), the on-system rules, and related lookups. Commands are bare subcommands for the caller to render with its own invocation. |
@@ -517,7 +517,7 @@ Every response has a `type` discriminant. The full set is below (generated from
517
517
  | `theme.eject` | A local source-fork receipt with the resolved slug, displayName, source theme maintained flag, source-selector package, outputDir, source entry, exportName, and every file written, including the descriptor. The written local descriptor always uses maintained: false. |
518
518
  | `theme.template` | A write receipt for the annotated theme template: the path (relative to cwd), whether it was written, and the reason it was not. `exists` when a file was already there, which is a success. |
519
519
  | `theme.targets` | The whole themeable surface: the echoed filter, componentCount, and targets, one per theming target — {key, className, component, props, states}, where props and states are its legal override keys. |
520
- | `theme.palette.generate` | An author-reviewable OKLCH palette candidate, its reproducibility receipt, summary counts, and optional candidate/receipt file-write result. |
520
+ | `theme.palette.generate` | An author-reviewable OKLCH palette response: recipe (`astryx-oklch-v1`), status (`candidate`), familyCount, stopCount, modes, candidate (`TonalPaletteCandidate`), and generationReceipt. The generationReceipt contains schemaVersion (1), recipe, generatorVersion (`palette-generator-v1`), candidateFormatVersion (`palette-typescript-v1` or `palette-json-v1`), candidateSha256, optional preview, resolved request, and diagnostics. File-write fields are output, receipt, preview, written, and reason (`exists` or null). |
521
521
  | `upgrade.list` | Every available codemod, oldest→newest, as {name, package, title, version, optional}; returned for --list without running anything. |
522
522
  | `upgrade.registry` | The copied-composition receipt for --registry: applied, ok, the counts (found, current, wouldUpdate, updated, wouldMerge, merged, wouldRefreshReceipt, receiptsRefreshed, conflicts, missing, invalid, failed), and items. |
523
523
  | `upgrade.status` | A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. no_codemods and config_fixable carry cliBehindCore ({cliVersion, command}) when the installed Core is newer than the CLI, which then has no codemods for the releases after its own version. |
@@ -27,10 +27,7 @@ import {
27
27
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
28
28
  import {projectAddCommand} from '../../foundation/release/notices.mjs';
29
29
  import {hostedRun} from '../../foundation/runtime/package-root.mjs';
30
- import {
31
- scanAllPackages,
32
- findComponentInPackages,
33
- } from './_package-scanner.mjs';
30
+ import {scanAllPackages, findComponentInPackages} from './_package-scanner.mjs';
34
31
  import {loadDocs} from '../../foundation/discovery/component-loader.mjs';
35
32
  import {collectIdentities} from '../../foundation/integrations/contribution-inventory.mjs';
36
33
  import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
@@ -146,8 +143,7 @@ function validateDocs(docs) {
146
143
  return 'docs.name is missing or not a string';
147
144
  if (!d.usage || typeof d.usage.description !== 'string')
148
145
  return 'docs.usage.description is missing or not a string';
149
- if (d.props && !Array.isArray(d.props))
150
- return 'docs.props must be an array';
146
+ if (d.props && !Array.isArray(d.props)) return 'docs.props must be an array';
151
147
  if (d.components && !Array.isArray(d.components))
152
148
  return 'docs.components must be an array';
153
149
  if (d.usage?.bestPractices && !Array.isArray(d.usage.bestPractices))
@@ -286,6 +282,7 @@ export async function computerAvailableEntries(project, installed, declared) {
286
282
  const have = new Set([...installed.map(pkg => pkg.name), ...declared]);
287
283
  return (await availableComputerIntegrations(cwd, have)).map(c => ({
288
284
  name: c.name,
285
+ package: c.name,
289
286
  components: [],
290
287
  ...(c.version ? {version: c.version} : {}),
291
288
  ...(c.description ? {description: c.description} : {}),
@@ -597,7 +594,10 @@ async function callOwnSources(project, request = {}, options = {}) {
597
594
  }
598
595
  for (const integration of project?.loadedIntegrations ?? []) {
599
596
  if (integration.__discoverError) {
600
- origins.push({from: integration.name, error: integration.__discoverError});
597
+ origins.push({
598
+ from: integration.name,
599
+ error: integration.__discoverError,
600
+ });
601
601
  } else if (integration.__discover) {
602
602
  origins.push({from: integration.name, source: integration.__discover});
603
603
  }
@@ -617,7 +617,10 @@ async function callOwnSources(project, request = {}, options = {}) {
617
617
  /** @type {Set<string>} */
618
618
  const seen = new Set();
619
619
  const ask = request.package
620
- ? {package: request.package, ...(request.version ? {version: request.version} : {})}
620
+ ? {
621
+ package: request.package,
622
+ ...(request.version ? {version: request.version} : {}),
623
+ }
621
624
  : {};
622
625
  for (const {from, key = from, source, error} of origins) {
623
626
  if (source == null) {
@@ -645,7 +648,12 @@ async function callOwnSources(project, request = {}, options = {}) {
645
648
  const message = err instanceof Error ? err.message : String(err);
646
649
  const saved = readSavedCopy(file, label);
647
650
  if (saved == null) {
648
- result.sources.push({name: from, from, status: 'failed', error: message});
651
+ result.sources.push({
652
+ name: from,
653
+ from,
654
+ status: 'failed',
655
+ error: message,
656
+ });
649
657
  continue;
650
658
  }
651
659
  catalog = saved.catalog;
@@ -940,6 +948,7 @@ export function toEntry(pkg) {
940
948
  /** @type {Record<string, unknown>} */
941
949
  const entry = {
942
950
  name: pkg.name,
951
+ package: pkg.name,
943
952
  category: pkg.category,
944
953
  components: pkg.components,
945
954
  version: pkg.version,
@@ -979,7 +988,10 @@ export async function loadValidatedDoc(result, {lang, zh}) {
979
988
  try {
980
989
  docs = await loadDocs(
981
990
  result.docPath,
982
- /** @type {{zh?: boolean, dense?: boolean, lang?: string}} */ ({zh, lang}),
991
+ /** @type {{zh?: boolean, dense?: boolean, lang?: string}} */ ({
992
+ zh,
993
+ lang,
994
+ }),
983
995
  );
984
996
  } catch (e) {
985
997
  throw new AstryxError(
@@ -63,6 +63,7 @@ export function catalogEntry(pkg: CatalogPackage, version: string | undefined):
63
63
  description?: string | undefined;
64
64
  version?: string | undefined;
65
65
  name: string;
66
+ package: string;
66
67
  category: string;
67
68
  components: string[];
68
69
  };
@@ -85,6 +86,7 @@ export function availableEntries(catalog: CatalogResult, installed: InstalledPac
85
86
  description?: string | undefined;
86
87
  version?: string | undefined;
87
88
  name: string;
89
+ package: string;
88
90
  components: string[];
89
91
  }[];
90
92
  /**
@@ -102,6 +102,7 @@ export function catalogEntry(pkg, version) {
102
102
  const {components, ...others} = kindLists(pkg.contributions);
103
103
  return {
104
104
  name: pkg.package,
105
+ package: pkg.package,
105
106
  category: pkg.package,
106
107
  components,
107
108
  ...(version ? {version} : {}),
@@ -74,6 +74,7 @@ describe('availableEntries', () => {
74
74
  it('describes an entry the way an installed one is described', () => {
75
75
  expect(availableEntries(CATALOG, [], new Set())[1]).toEqual({
76
76
  name: '@acme/charts',
77
+ package: '@acme/charts',
77
78
  components: [],
78
79
  version: '2.0.0',
79
80
  themes: ['ocean'],
@@ -80,6 +80,7 @@ export function detail(packages, name, options = {}) {
80
80
  if (catalog) data.versions = catalog.versions;
81
81
  return {
82
82
  type: 'discover.detail',
83
+ package: String(data.name),
83
84
  data: /** @type {import('../discover.type.mjs').DiscoverDetailResponse['data']} */ (
84
85
  data
85
86
  ),
@@ -31,8 +31,10 @@ describe('discover.detail leaf', () => {
31
31
  it('projects the matched package into a detail entry', () => {
32
32
  const res = detail(PACKAGES, '@acme/widgets');
33
33
  expect(res.type).toBe('discover.detail');
34
+ expect(res.package).toBe('@acme/widgets');
34
35
  expect(res.data).toEqual({
35
36
  name: '@acme/widgets',
37
+ package: '@acme/widgets',
36
38
  category: '@acme/widgets',
37
39
  components: ['Alpha', 'Beta'],
38
40
  version: '1.2.3',
@@ -81,6 +83,7 @@ describe('discover.detail leaf with a discover source', () => {
81
83
  it('describes a package the project does not have, with the command that adds it', () => {
82
84
  expect(detail(PACKAGES, '@acme/charts', {catalog, add}).data).toEqual({
83
85
  name: '@acme/charts',
86
+ package: '@acme/charts',
84
87
  category: '@acme/charts',
85
88
  components: ['Chart'],
86
89
  version: '2.0.0',
@@ -35,7 +35,11 @@ export async function docFromResult(result, opts) {
35
35
  {type: 'component.detail', package: result.pkg.name, data},
36
36
  process.cwd(),
37
37
  );
38
- return {type: 'discover.detail.doc', data: linked.data};
38
+ return {
39
+ type: 'discover.detail.doc',
40
+ package: result.pkg.name,
41
+ data: linked.data,
42
+ };
39
43
  }
40
44
 
41
45
  /**
@@ -86,6 +86,7 @@ describe('discover.detail.doc leaf', () => {
86
86
  );
87
87
  expect(res).toEqual({
88
88
  type: 'discover.detail.doc',
89
+ package: '@acme/widgets',
89
90
  data: {name: 'Beta', usage: {description: 'Beta component'}, props: []},
90
91
  });
91
92
  });
@@ -39,6 +39,7 @@ export function item(packages, packageName, itemName, options = {}) {
39
39
  if (Array.isArray(names) && names.includes(itemName)) {
40
40
  return {
41
41
  type: 'discover.item',
42
+ package: packageName,
42
43
  data: {
43
44
  package: packageName,
44
45
  ...(pkg.version ? {version: pkg.version} : {}),
@@ -59,6 +60,7 @@ export function item(packages, packageName, itemName, options = {}) {
59
60
  const shown = version ?? defaultVersion(catalog);
60
61
  return {
61
62
  type: 'discover.item',
63
+ package: packageName,
62
64
  data: {
63
65
  package: packageName,
64
66
  ...(shown ? {version: shown} : {}),
@@ -38,6 +38,7 @@ describe('discover.item leaf', () => {
38
38
  it("finds an installed package's own template, doc, theme, or codemod", () => {
39
39
  expect(item(PACKAGES, '@acme/widgets', 'pages/Home')).toEqual({
40
40
  type: 'discover.item',
41
+ package: '@acme/widgets',
41
42
  data: {
42
43
  package: '@acme/widgets',
43
44
  version: '1.2.3',
@@ -53,6 +54,7 @@ describe('discover.item leaf', () => {
53
54
  item(PACKAGES, '@acme/charts', 'pages/report', {catalog: CATALOG, add}),
54
55
  ).toEqual({
55
56
  type: 'discover.item',
57
+ package: '@acme/charts',
56
58
  data: {
57
59
  package: '@acme/charts',
58
60
  version: '2.0.0',
@@ -91,22 +91,22 @@ export const doc = {
91
91
  {
92
92
  type: 'discover.list',
93
93
  description:
94
- 'What the project has: the integrations it loads and the official packages it declares (name, category, components, version, and a list per other kind they add), official packages first. meta.available lists what the project could add, official packages first, each with the command that adds it; inside a project, an integration installed for the computer that the project does not install is listed there too, with source `installed for this computer` and the install command for the project in `install`. meta.sources reports each source, the official list last. When it lists no integration it carries meta.configured.',
94
+ 'What the project has: the integrations it loads and the official packages it declares (package, the npm package and always equal to name; name, category, components, version, and a list per other kind they add), official packages first. meta.available lists what the project could add, official packages first, each with its package and the command that adds it; inside a project, an integration installed for the computer that the project does not install is listed there too, with source `installed for this computer` and the install command for the project in `install`. meta.sources reports each source, the official list last. When it lists no integration it carries meta.configured.',
95
95
  },
96
96
  {
97
97
  type: 'discover.detail',
98
98
  description:
99
- "One package: what the shown version adds, whether the project has it, its versions and latest release when a source knows them, and the command that adds it when the project does not have it. An entry from the official list lists the newest release this CLI knows as latest and the project's Core version; its add command pins the project's Core version, else the Core range it declares (quoted), else the latest release. A version or item the official list does not show answers ERR_UNKNOWN_PACKAGE.",
99
+ "One package: its package (the npm package the result is about), what the shown version adds, whether the project has it, its versions and latest release when a source knows them, and the command that adds it when the project does not have it. An entry from the official list lists the newest release this CLI knows as latest and the project's Core version; its add command pins the project's Core version, else the Core range it declares (quoted), else the latest release. A version or item the official list does not show answers ERR_UNKNOWN_PACKAGE.",
100
100
  },
101
101
  {
102
102
  type: 'discover.detail.doc',
103
103
  description:
104
- 'The validated ComponentDoc for one installed component, for an @scope/name/Component query.',
104
+ 'The validated ComponentDoc for one installed component, for an @scope/name/Component query, plus package, the npm package that owns the component.',
105
105
  },
106
106
  {
107
107
  type: 'discover.item',
108
108
  description:
109
- 'One item that is not an installed component: its kind, name, the package and version that add it, and whether the project has the package.',
109
+ 'One item that is not an installed component: its kind, name, the package and version that add it, and whether the project has the package. The envelope\'s package names the same package.',
110
110
  },
111
111
  {
112
112
  type: 'discover.search',
@@ -42,6 +42,10 @@ export type DiscoverListMeta = {
42
42
  */
43
43
  export type DiscoverListEntry = {
44
44
  name: string;
45
+ /**
46
+ * The npm package — always equal to `name`.
47
+ */
48
+ package: string;
45
49
  category: string;
46
50
  components: string[];
47
51
  version?: string | undefined;
@@ -77,6 +81,10 @@ export type DiscoverListEntry = {
77
81
  */
78
82
  export type DiscoverAvailableEntry = {
79
83
  name: string;
84
+ /**
85
+ * The npm package — always equal to `name`.
86
+ */
87
+ package: string;
80
88
  /**
81
89
  * Its latest release.
82
90
  */
@@ -127,6 +135,10 @@ export type DiscoverSourceState = {
127
135
  */
128
136
  export type DiscoverDetailResponse = {
129
137
  type: "discover.detail";
138
+ /**
139
+ * The npm package this result is about.
140
+ */
141
+ package: string;
130
142
  /**
131
143
  * `installed` says whether the project has the package;
132
144
  * `installedVersion` is set when it has another version than the one shown.
@@ -150,6 +162,10 @@ export type DiscoverDetailResponse = {
150
162
  */
151
163
  export type DiscoverDetailDocResponse = {
152
164
  type: "discover.detail.doc";
165
+ /**
166
+ * The npm package that owns the component.
167
+ */
168
+ package: string;
153
169
  data: import("@astryxdesign/cli/authoring").ComponentDoc;
154
170
  };
155
171
  /**
@@ -157,6 +173,10 @@ export type DiscoverDetailDocResponse = {
157
173
  */
158
174
  export type DiscoverItemResponse = {
159
175
  type: "discover.item";
176
+ /**
177
+ * The npm package that owns the item.
178
+ */
179
+ package: string;
160
180
  data: {
161
181
  package: string;
162
182
  version?: string;
@@ -44,6 +44,7 @@
44
44
  * An installed integration, or an official package the project declares.
45
45
  * @typedef {object} DiscoverListEntry
46
46
  * @property {string} name
47
+ * @property {string} package The npm package — always equal to `name`.
47
48
  * @property {string} category
48
49
  * @property {string[]} components
49
50
  * @property {string} [version]
@@ -61,6 +62,7 @@
61
62
  * A package the project could add.
62
63
  * @typedef {object} DiscoverAvailableEntry
63
64
  * @property {string} name
65
+ * @property {string} package The npm package — always equal to `name`.
64
66
  * @property {string} [version] Its latest release.
65
67
  * @property {string[]} components
66
68
  * @property {string[]} [templates]
@@ -95,6 +97,7 @@
95
97
  * astryx --json discover @scope/name[@version]
96
98
  * @typedef {object} DiscoverDetailResponse
97
99
  * @property {'discover.detail'} type
100
+ * @property {string} package The npm package this result is about.
98
101
  * @property {DiscoverListEntry & {
99
102
  * installed: boolean,
100
103
  * installedVersion?: string,
@@ -115,6 +118,7 @@
115
118
  * astryx --json discover @scope/name/Component
116
119
  * @typedef {object} DiscoverDetailDocResponse
117
120
  * @property {'discover.detail.doc'} type
121
+ * @property {string} package The npm package that owns the component.
118
122
  * @property {import('@astryxdesign/cli/authoring').ComponentDoc} data
119
123
  */
120
124
 
@@ -123,6 +127,7 @@
123
127
  * installed component.
124
128
  * @typedef {object} DiscoverItemResponse
125
129
  * @property {'discover.item'} type
130
+ * @property {string} package The npm package that owns the item.
126
131
  * @property {{
127
132
  * package: string,
128
133
  * version?: string,
@@ -32,6 +32,7 @@ describe('discover.list leaf', () => {
32
32
  expect(res.data).toEqual([
33
33
  {
34
34
  name: '@acme/widgets',
35
+ package: '@acme/widgets',
35
36
  category: '@acme/widgets',
36
37
  components: ['Alpha', 'Beta'],
37
38
  version: '1.2.3',
@@ -77,6 +78,7 @@ describe('discover.list leaf with discover sources', () => {
77
78
  expect(res.data).toEqual([
78
79
  {
79
80
  name: '@acme/widgets',
81
+ package: '@acme/widgets',
80
82
  category: '@acme/widgets',
81
83
  components: ['Alpha'],
82
84
  version: '1.2.3',
@@ -4,8 +4,9 @@
4
4
  /**
5
5
  * Search all packages for `query` (a free-text term that never starts with
6
6
  * `@`). Resolves to a search response when anything matches, even a single
7
- * item or an exact component name, or throws AstryxError (ERR_NOT_FOUND) —
8
- * with fuzzy suggestions when any exist.
7
+ * item, an exact component name or a near-miss name long enough to be a
8
+ * typo, or throws AstryxError (ERR_NOT_FOUND) — with fuzzy suggestions when
9
+ * any exist.
9
10
  *
10
11
  * @param {ScannedPackage[]} packages installed packages
11
12
  * @param {string} query
@@ -6,9 +6,12 @@
6
6
  *
7
7
  * A free-text query always answers with a list, so its response type depends
8
8
  * on the form of the query and never on what the project has:
9
- * 1. any matches -> discover.search
10
- * 2. fuzzy hits (distance <= 3) -> throw ERR_NOT_FOUND with suggestions
11
- * 3. otherwise -> throw ERR_NOT_FOUND
9
+ * 1. any matches, a near-miss name included -> discover.search (a one- to
10
+ * three-edit miss counts when both words are long enough: 5, 8 and 11
11
+ * letters)
12
+ * 2. other fuzzy hits (distance <= 3) -> throw ERR_NOT_FOUND with
13
+ * suggestions
14
+ * 3. otherwise -> throw ERR_NOT_FOUND
12
15
  * Matches are installed components, the project's other installed items,
13
16
  * packages, and every item a source lists for a package the project could add.
14
17
  * A caller opens one item by its package path, which ../detail answers.
@@ -31,7 +34,8 @@ const KIND_ORDER = ['package', ...DISCOVER_KINDS];
31
34
 
32
35
  /**
33
36
  * How well an item matches: 0 exact name, 1 name prefix, 2 name substring,
34
- * 3 title, summary, keyword, or description; null for no match.
37
+ * 3 a near-miss name (3.0, 3.1, 3.2 for one, two or three edits), 4 title,
38
+ * summary, keyword, or description; null for no match.
35
39
  * @param {SearchItem} item
36
40
  * @param {string} lower
37
41
  * @returns {number | null}
@@ -41,6 +45,19 @@ function rank(item, lower) {
41
45
  if (name === lower) return 0;
42
46
  if (name.startsWith(lower)) return 1;
43
47
  if (name.includes(lower)) return 2;
48
+ // A near-miss name ranks above a match in the title or text: how closely
49
+ // the name matches decides first (AST-051 FR4).
50
+ // Typo tolerance: same minimum-length guards as search (api/search/search.mjs).
51
+ // A one-edit miss is a typo only on words long enough that one edit rarely
52
+ // makes a different real word.
53
+ const dist = levenshteinDistance(lower, name);
54
+ if (dist >= 1 && dist <= 3) {
55
+ /** @type {Record<number, number>} */
56
+ const MIN_LENGTHS = {1: 5, 2: 8, 3: 11};
57
+ if (Math.min(lower.length, name.length) >= MIN_LENGTHS[dist]) {
58
+ return 3 + (dist - 1) / 10;
59
+ }
60
+ }
44
61
  const text = [
45
62
  item.title,
46
63
  item.summary,
@@ -50,14 +67,16 @@ function rank(item, lower) {
50
67
  .filter(Boolean)
51
68
  .join('\n')
52
69
  .toLowerCase();
53
- return text.includes(lower) ? 3 : null;
70
+ if (text.includes(lower)) return 4;
71
+ return null;
54
72
  }
55
73
 
56
74
  /**
57
75
  * Search all packages for `query` (a free-text term that never starts with
58
76
  * `@`). Resolves to a search response when anything matches, even a single
59
- * item or an exact component name, or throws AstryxError (ERR_NOT_FOUND) —
60
- * with fuzzy suggestions when any exist.
77
+ * item, an exact component name or a near-miss name long enough to be a
78
+ * typo, or throws AstryxError (ERR_NOT_FOUND) — with fuzzy suggestions when
79
+ * any exist.
61
80
  *
62
81
  * @param {ScannedPackage[]} packages installed packages
63
82
  * @param {string} query
@@ -142,6 +142,73 @@ describe('discover.search leaf — empty query (parity with api/search)', () =>
142
142
  });
143
143
  });
144
144
 
145
+ describe('discover.search leaf — typo tolerance (parity with api/search)', () => {
146
+ it('a one-edit miss on a 5+ letter name returns results, not ERR_NOT_FOUND', async () => {
147
+ // 'Alphe' is one substitution from 'Alpha' (distance 1, both >= 5 chars)
148
+ const res = await search(packages, 'Alphe', {});
149
+ expect(res.type).toBe('discover.search');
150
+ expect(res.data.matches.map(m => m.component)).toContain('Alpha');
151
+ });
152
+
153
+ it("ranks a near-miss name above a match in another item's text", async () => {
154
+ const items = [
155
+ {
156
+ package: '@acme/charts',
157
+ kind: 'component',
158
+ name: 'Scheduler',
159
+ description: 'Lighter than a Calendr widget',
160
+ installed: false,
161
+ },
162
+ {
163
+ package: '@acme/charts',
164
+ kind: 'component',
165
+ name: 'Calendar',
166
+ installed: false,
167
+ },
168
+ ];
169
+ // 'Calendr' is one edit from the name 'Calendar' and appears word for
170
+ // word only in Scheduler's description.
171
+ const res = await search(packages, 'Calendr', {items});
172
+ const names = res.data.matches.map(m => m.component);
173
+ expect(names.indexOf('Calendar')).toBeGreaterThanOrEqual(0);
174
+ expect(names.indexOf('Calendar')).toBeLessThan(names.indexOf('Scheduler'));
175
+ });
176
+
177
+ it('orders near misses by how many edits away they are', async () => {
178
+ const items = [
179
+ {package: '@acme/charts', kind: 'component', name: 'Paginaters', installed: false},
180
+ {package: '@acme/charts', kind: 'component', name: 'Paginator', installed: false},
181
+ ];
182
+ const res = await search(packages, 'Paginatr', {items});
183
+ const names = res.data.matches.map(m => m.component);
184
+ expect(names.indexOf('Paginator')).toBeLessThan(names.indexOf('Paginaters'));
185
+ });
186
+
187
+ it('a one-edit miss on a longer name returns results', async () => {
188
+ // 'AlpheCard' vs 'AlphaCard' is distance 1, well above 5 chars
189
+ const res = await search(packages, 'AlpheCard', {});
190
+ expect(res.type).toBe('discover.search');
191
+ expect(res.data.matches.map(m => m.component)).toContain('AlphaCard');
192
+ });
193
+
194
+ it('a short word with distance 1 still throws (below min-length guard)', async () => {
195
+ // 'Betz' vs 'Beta' is distance 1, but both are only 4 chars (< 5)
196
+ await expect(search(packages, 'Betz', {})).rejects.toMatchObject({
197
+ code: 'ERR_NOT_FOUND',
198
+ });
199
+ });
200
+
201
+ it('includes catalog items in fuzzy matches too', async () => {
202
+ const items = [
203
+ {package: '@acme/charts', kind: 'component', name: 'Alphabets', installed: false},
204
+ ];
205
+ // 'Alphabel' vs 'Alphabets' is distance 2, both >= 8 chars
206
+ const res = await search(packages, 'Alphabel', {items});
207
+ expect(res.type).toBe('discover.search');
208
+ expect(res.data.matches.map(m => m.component)).toContain('Alphabets');
209
+ });
210
+ });
211
+
145
212
  describe('discover.search leaf across every kind and source', () => {
146
213
  /** @type {any[]} */
147
214
  const items = [
@@ -230,7 +230,12 @@ export function parseNpmPackOutput(output) {
230
230
  throw new Error('npm pack returned a result without a files array.');
231
231
  }
232
232
  return {
233
- filename: info.filename,
233
+ // npm 8 names a scoped package's tarball `@scope/name-1.0.0.tgz` in its
234
+ // JSON but writes `scope-name-1.0.0.tgz`, as every later npm reports.
235
+ filename:
236
+ typeof info.filename === 'string' && /^@[^/]+\//.test(info.filename)
237
+ ? info.filename.slice(1).replace('/', '-')
238
+ : info.filename,
234
239
  fileCount: info.entryCount,
235
240
  size: info.size,
236
241
  unpackedSize: info.unpackedSize,
@@ -2038,6 +2038,20 @@ describe('integrationPackCheck', () => {
2038
2038
  ).toEqual([]);
2039
2039
  });
2040
2040
 
2041
+ it("reads npm 8's scoped tarball name as the file npm writes", () => {
2042
+ const entry = {entryCount: 1, size: 1, unpackedSize: 1, files: []};
2043
+ expect(
2044
+ parseNpmPackOutput(
2045
+ JSON.stringify([{...entry, filename: '@acme/kit-1.0.0.tgz'}]),
2046
+ ).filename,
2047
+ ).toBe('acme-kit-1.0.0.tgz');
2048
+ expect(
2049
+ parseNpmPackOutput(
2050
+ JSON.stringify([{...entry, filename: 'acme-kit-1.0.0.tgz'}]),
2051
+ ).filename,
2052
+ ).toBe('acme-kit-1.0.0.tgz');
2053
+ });
2054
+
2041
2055
  it('rejects malformed npm pack output without a raw TypeError', () => {
2042
2056
  expect(() =>
2043
2057
  parseNpmPackOutput(
@@ -18,6 +18,10 @@ export function themePaletteGenerate(configPath: string, options?: {
18
18
  }, { cwd }?: {
19
19
  cwd?: string;
20
20
  }): import("../../theme.type.mjs").ThemePaletteGenerateResponse;
21
+ /** Format of the TypeScript candidate module written for a `.ts` output. */
22
+ export const PALETTE_TYPESCRIPT_FORMAT_VERSION: "palette-typescript-v1";
23
+ /** Format of the canonical JSON candidate the recipe fixtures pin. */
24
+ export const PALETTE_JSON_FORMAT_VERSION: "palette-json-v1";
21
25
  export type TonalPaletteCandidate = import("../../theme.type.mjs").TonalPaletteCandidate;
22
26
  export type TonalPaletteGenerationInput = import("../../theme.type.mjs").TonalPaletteGenerationInput;
23
27
  export type PaletteMode = "light" | "dark";
@@ -26,4 +30,8 @@ export type PendingFile = {
26
30
  path: string;
27
31
  next: string;
28
32
  };
33
+ export type SerializedCandidate = {
34
+ format: typeof PALETTE_TYPESCRIPT_FORMAT_VERSION | typeof PALETTE_JSON_FORMAT_VERSION;
35
+ text: string;
36
+ };
29
37
  import { generatePaletteSet } from './generator.mjs';
@@ -12,16 +12,23 @@ import {AstryxError} from '../../../error.mjs';
12
12
  import {
13
13
  generatePaletteSet,
14
14
  PALETTE_BLACK,
15
+ PALETTE_GENERATOR_VERSION,
15
16
  PALETTE_WHITE,
16
17
  serializeGenerationResult,
17
18
  } from './generator.mjs';
18
19
  import {PALETTE_PREVIEW_VERSION, renderPalettePreview} from './preview.mjs';
19
20
 
21
+ /** Format of the TypeScript candidate module written for a `.ts` output. */
22
+ export const PALETTE_TYPESCRIPT_FORMAT_VERSION = 'palette-typescript-v1';
23
+ /** Format of the canonical JSON candidate the recipe fixtures pin. */
24
+ export const PALETTE_JSON_FORMAT_VERSION = 'palette-json-v1';
25
+
20
26
  /** @typedef {import('../../theme.type.mjs').TonalPaletteCandidate} TonalPaletteCandidate */
21
27
  /** @typedef {import('../../theme.type.mjs').TonalPaletteGenerationInput} TonalPaletteGenerationInput */
22
28
  /** @typedef {'light' | 'dark'} PaletteMode */
23
29
  /** @typedef {ReturnType<typeof generatePaletteSet>} PaletteGenerationResult */
24
30
  /** @typedef {{path: string, next: string}} PendingFile */
31
+ /** @typedef {{format: typeof PALETTE_TYPESCRIPT_FORMAT_VERSION | typeof PALETTE_JSON_FORMAT_VERSION, text: string}} SerializedCandidate */
25
32
 
26
33
  /** @param {PaletteGenerationResult} result @returns {TonalPaletteCandidate} */
27
34
  function paletteSnapshot(result) {
@@ -90,10 +97,28 @@ export function serializePaletteCandidate(candidate) {
90
97
  return `{\n "schemaVersion": 1,\n "status": "candidate",\n "recipe": ${JSON.stringify(candidate.recipe)},\n "black": ${JSON.stringify(candidate.black)},\n "white": ${JSON.stringify(candidate.white)},\n "stops": [\n${stops.join(',\n')}\n ],\n "palette": ${serializePalette(candidate.palette, 2)}\n}\n`;
91
98
  }
92
99
 
93
- /** @param {TonalPaletteCandidate} candidate @param {string} outputPath */
100
+ /**
101
+ * Serialize a candidate for its destination and name the format of the exact
102
+ * bytes produced. Without a destination, the canonical JSON form identifies
103
+ * the candidate.
104
+ *
105
+ * @param {TonalPaletteCandidate} candidate
106
+ * @param {string | null} outputPath
107
+ * @returns {SerializedCandidate}
108
+ */
94
109
  function serializeCandidate(candidate, outputPath) {
95
- if (outputPath.endsWith('.ts')) return serializePaletteModule(candidate);
96
- if (outputPath.endsWith('.json')) return serializePaletteCandidate(candidate);
110
+ if (outputPath != null && outputPath.endsWith('.ts')) {
111
+ return {
112
+ format: PALETTE_TYPESCRIPT_FORMAT_VERSION,
113
+ text: serializePaletteModule(candidate),
114
+ };
115
+ }
116
+ if (outputPath == null || outputPath.endsWith('.json')) {
117
+ return {
118
+ format: PALETTE_JSON_FORMAT_VERSION,
119
+ text: serializePaletteCandidate(candidate),
120
+ };
121
+ }
97
122
  throw new AstryxError(
98
123
  'Palette output must end in .ts or .json.',
99
124
  undefined,
@@ -101,12 +126,14 @@ function serializeCandidate(candidate, outputPath) {
101
126
  );
102
127
  }
103
128
 
104
- /** @param {PaletteGenerationResult} result @param {string} candidateText @param {string | null} [previewText] @returns {import('../../theme.type.mjs').TonalPaletteGenerationReceipt} */
105
- function receiptFor(result, candidateText, previewText = null) {
129
+ /** @param {PaletteGenerationResult} result @param {SerializedCandidate} serialized @param {string | null} [previewText] @returns {import('../../theme.type.mjs').TonalPaletteGenerationReceipt} */
130
+ function receiptFor(result, serialized, previewText = null) {
106
131
  return {
107
132
  schemaVersion: 1,
108
133
  recipe: result.recipe,
109
- candidateSha256: createHash('sha256').update(candidateText).digest('hex'),
134
+ generatorVersion: PALETTE_GENERATOR_VERSION,
135
+ candidateFormatVersion: serialized.format,
136
+ candidateSha256: createHash('sha256').update(serialized.text).digest('hex'),
110
137
  ...(previewText
111
138
  ? {
112
139
  preview: {
@@ -345,9 +372,9 @@ export function themePaletteGenerate(
345
372
  }
346
373
 
347
374
  const candidate = paletteSnapshot(result);
348
- let candidateText = serializePaletteCandidate(candidate);
375
+ let serialized = serializeCandidate(candidate, null);
349
376
  const previewText = options.preview ? renderPalettePreview(candidate) : null;
350
- let receipt = receiptFor(result, candidateText, previewText);
377
+ let receipt = receiptFor(result, serialized, previewText);
351
378
  /** @type {string | null} */
352
379
  let output = null;
353
380
  /** @type {string | null} */
@@ -363,13 +390,13 @@ export function themePaletteGenerate(
363
390
  if (options.out) {
364
391
  const resolvedOutput = resolveSafe(options.out, cwd, 'palette output path');
365
392
  const resolvedReceipt = receiptPathFor(resolvedOutput);
366
- candidateText = serializeCandidate(candidate, resolvedOutput);
367
- receipt = receiptFor(result, candidateText, previewText);
393
+ serialized = serializeCandidate(candidate, resolvedOutput);
394
+ receipt = receiptFor(result, serialized, previewText);
368
395
  const receiptText = serializeGenerationResult(receipt);
369
396
  output = path.relative(cwd, resolvedOutput);
370
397
  receiptOutput = path.relative(cwd, resolvedReceipt);
371
398
  files.push(
372
- {path: resolvedOutput, next: candidateText},
399
+ {path: resolvedOutput, next: serialized.text},
373
400
  {path: resolvedReceipt, next: receiptText},
374
401
  );
375
402
  }
@@ -6,7 +6,12 @@ import * as os from 'node:os';
6
6
  import * as path from 'node:path';
7
7
  import {afterEach, describe, expect, it} from 'vitest';
8
8
  import {isErrorCode} from '../../../../foundation/response/error-codes.mjs';
9
- import {themePaletteGenerate} from './generate.mjs';
9
+ import {
10
+ PALETTE_JSON_FORMAT_VERSION,
11
+ PALETTE_TYPESCRIPT_FORMAT_VERSION,
12
+ themePaletteGenerate,
13
+ } from './generate.mjs';
14
+ import {PALETTE_GENERATOR_VERSION} from './generator.mjs';
10
15
 
11
16
  const temporaryDirectories = [];
12
17
 
@@ -79,7 +84,12 @@ describe('themePaletteGenerate', () => {
79
84
  fs.readFileSync(path.join(cwd, 'ocean.palette.receipt.json'), 'utf-8'),
80
85
  );
81
86
  expect(receipt.recipe).toBe('astryx-oklch-v1');
82
- expect(receipt.candidateSha256).toMatch(/^[0-9a-f]{64}$/);
87
+ expect(receipt.generatorVersion).toBe('palette-generator-v1');
88
+ expect(receipt.candidateFormatVersion).toBe('palette-typescript-v1');
89
+ expect(receipt.candidateSha256).toBe(
90
+ createHash('sha256').update(candidate).digest('hex'),
91
+ );
92
+ expect(receipt).toEqual(result.data.generationReceipt);
83
93
  expect(candidate).toContain('// prettier-ignore');
84
94
  expect(candidate).toContain("export const black = '#000000' as const;");
85
95
  expect(candidate).toContain("export const white = '#ffffff' as const;");
@@ -103,6 +113,69 @@ describe('themePaletteGenerate', () => {
103
113
  expect(result.data.receipt).toBe('ocean.palette.receipt.json');
104
114
  });
105
115
 
116
+ it('names the generator and the format of the exact bytes each receipt covers', () => {
117
+ expect(PALETTE_GENERATOR_VERSION).toBe('palette-generator-v1');
118
+ expect(PALETTE_TYPESCRIPT_FORMAT_VERSION).toBe('palette-typescript-v1');
119
+ expect(PALETTE_JSON_FORMAT_VERSION).toBe('palette-json-v1');
120
+
121
+ const cwd = fixture();
122
+ const sha256 = file =>
123
+ createHash('sha256')
124
+ .update(fs.readFileSync(path.join(cwd, file)))
125
+ .digest('hex');
126
+ const printed = themePaletteGenerate('palette.config.json', {}, {cwd}).data
127
+ .generationReceipt;
128
+ const typescript = themePaletteGenerate(
129
+ 'palette.config.json',
130
+ {out: 'ocean.palette.ts'},
131
+ {cwd},
132
+ ).data.generationReceipt;
133
+ const json = themePaletteGenerate(
134
+ 'palette.config.json',
135
+ {out: 'ocean-json.palette.json'},
136
+ {cwd},
137
+ ).data.generationReceipt;
138
+
139
+ // Existing receipt fields keep their positions; the versions sit beside
140
+ // the digest they qualify.
141
+ expect(Object.keys(typescript)).toEqual([
142
+ 'schemaVersion',
143
+ 'recipe',
144
+ 'generatorVersion',
145
+ 'candidateFormatVersion',
146
+ 'candidateSha256',
147
+ 'request',
148
+ 'diagnostics',
149
+ ]);
150
+ expect(typescript).toMatchObject({
151
+ generatorVersion: PALETTE_GENERATOR_VERSION,
152
+ candidateFormatVersion: PALETTE_TYPESCRIPT_FORMAT_VERSION,
153
+ candidateSha256: sha256('ocean.palette.ts'),
154
+ });
155
+ expect(json).toMatchObject({
156
+ generatorVersion: PALETTE_GENERATOR_VERSION,
157
+ candidateFormatVersion: PALETTE_JSON_FORMAT_VERSION,
158
+ candidateSha256: sha256('ocean-json.palette.json'),
159
+ });
160
+ // Without an output path, the receipt covers the canonical JSON bytes.
161
+ expect(printed).toEqual(json);
162
+ // Only the serialized bytes differ between formats, never the generation.
163
+ expect(typescript.candidateSha256).not.toBe(json.candidateSha256);
164
+ expect({
165
+ ...typescript,
166
+ candidateFormatVersion: null,
167
+ candidateSha256: null,
168
+ }).toEqual({...json, candidateFormatVersion: null, candidateSha256: null});
169
+ for (const [file, receipt] of [
170
+ ['ocean.palette.receipt.json', typescript],
171
+ ['ocean-json.palette.receipt.json', json],
172
+ ]) {
173
+ expect(
174
+ JSON.parse(fs.readFileSync(path.join(cwd, file), 'utf-8')),
175
+ ).toEqual(receipt);
176
+ }
177
+ });
178
+
106
179
  it('writes candidate JSON byte-identical to the recipe fixtures', () => {
107
180
  const families = [
108
181
  {id: 'neutral', name: 'Neutral', seed: '#777777', kind: 'neutral'},
@@ -164,7 +237,10 @@ describe('themePaletteGenerate', () => {
164
237
  );
165
238
 
166
239
  const printed = themePaletteGenerate('palette.config.json', {}, {cwd});
167
- expect(printed.data.generationReceipt.candidateSha256).toBe(sha256);
240
+ expect(printed.data.generationReceipt).toMatchObject({
241
+ candidateFormatVersion: 'palette-json-v1',
242
+ candidateSha256: sha256,
243
+ });
168
244
 
169
245
  const result = themePaletteGenerate(
170
246
  'palette.config.json',
@@ -174,7 +250,10 @@ describe('themePaletteGenerate', () => {
174
250
  const written = fs.readFileSync(path.join(cwd, 'candidate.json'));
175
251
  expect(written.length).toBe(bytes);
176
252
  expect(createHash('sha256').update(written).digest('hex')).toBe(sha256);
177
- expect(result.data.generationReceipt.candidateSha256).toBe(sha256);
253
+ expect(result.data.generationReceipt).toMatchObject({
254
+ candidateFormatVersion: 'palette-json-v1',
255
+ candidateSha256: sha256,
256
+ });
178
257
  }
179
258
  });
180
259
 
@@ -34,6 +34,12 @@ export function serializeGenerationResult(result: unknown): string;
34
34
  /** @typedef {{id: string, name: string, seed: string, light?: GeneratedRamp, dark?: GeneratedRamp}} GeneratedFamily */
35
35
  /** @typedef {{recipe: typeof PALETTE_RECIPE, status: 'candidate', request: NormalizedRequest, families: GeneratedFamily[], coordination: TonalPaletteCoordinationDiagnostics[], errors: {familyId: string, message: string}[]}} PaletteGenerationResult */
36
36
  export const PALETTE_RECIPE: "astryx-oklch-v1";
37
+ /**
38
+ * Identity of this generator implementation. `PALETTE_RECIPE` names the
39
+ * normative algorithm; this names the code that ran it, so a receipt can tell
40
+ * two implementations of one recipe apart.
41
+ */
42
+ export const PALETTE_GENERATOR_VERSION: "palette-generator-v1";
37
43
  export const PALETTE_BLACK: "#000000";
38
44
  export const PALETTE_WHITE: "#ffffff";
39
45
  export const DEFAULT_21_STOPS: readonly number[];
@@ -25,6 +25,12 @@ import {
25
25
  /** @typedef {{recipe: typeof PALETTE_RECIPE, status: 'candidate', request: NormalizedRequest, families: GeneratedFamily[], coordination: TonalPaletteCoordinationDiagnostics[], errors: {familyId: string, message: string}[]}} PaletteGenerationResult */
26
26
 
27
27
  export const PALETTE_RECIPE = 'astryx-oklch-v1';
28
+ /**
29
+ * Identity of this generator implementation. `PALETTE_RECIPE` names the
30
+ * normative algorithm; this names the code that ran it, so a receipt can tell
31
+ * two implementations of one recipe apart.
32
+ */
33
+ export const PALETTE_GENERATOR_VERSION = 'palette-generator-v1';
28
34
  export const PALETTE_BLACK = '#000000';
29
35
  export const PALETTE_WHITE = '#ffffff';
30
36
  export const DEFAULT_21_STOPS = Object.freeze([
@@ -417,7 +417,18 @@ export type TonalPaletteGenerationReceipt = {
417
417
  */
418
418
  recipe: "astryx-oklch-v1";
419
419
  /**
420
- * SHA-256 over the candidate bytes as written.
420
+ * Generator
421
+ * implementation that ran the recipe.
422
+ */
423
+ generatorVersion: "palette-generator-v1";
424
+ /**
425
+ * Format of the candidate bytes `candidateSha256` covers: the TypeScript
426
+ * module for a `.ts` output, otherwise canonical JSON.
427
+ */
428
+ candidateFormatVersion: "palette-typescript-v1" | "palette-json-v1";
429
+ /**
430
+ * SHA-256 over the candidate bytes in
431
+ * `candidateFormatVersion`, exactly as written when an output path is given.
421
432
  */
422
433
  candidateSha256: string;
423
434
  /**
@@ -245,7 +245,13 @@
245
245
  * @typedef {object} TonalPaletteGenerationReceipt
246
246
  * @property {1} schemaVersion
247
247
  * @property {'astryx-oklch-v1'} recipe Recipe that produced the candidate.
248
- * @property {string} candidateSha256 SHA-256 over the candidate bytes as written.
248
+ * @property {'palette-generator-v1'} generatorVersion Generator
249
+ * implementation that ran the recipe.
250
+ * @property {'palette-typescript-v1' | 'palette-json-v1'} candidateFormatVersion
251
+ * Format of the candidate bytes `candidateSha256` covers: the TypeScript
252
+ * module for a `.ts` output, otherwise canonical JSON.
253
+ * @property {string} candidateSha256 SHA-256 over the candidate bytes in
254
+ * `candidateFormatVersion`, exactly as written when an output path is given.
249
255
  * @property {{version: string, sha256: string}} [preview] Present when preview
250
256
  * content was generated for the request, even if no file was written because
251
257
  * the target already exists.
@@ -61,7 +61,7 @@ export const doc = {
61
61
  {
62
62
  type: 'theme.palette.generate',
63
63
  description:
64
- 'The candidate, generation receipt, summary counts, and optional file-write receipt.',
64
+ 'The candidate, summary counts, optional file-write result, and generationReceipt. The generationReceipt identifies generatorVersion `palette-generator-v1` and candidateFormatVersion `palette-typescript-v1` or `palette-json-v1` beside the candidate digest.',
65
65
  },
66
66
  ],
67
67
  throws: [
@@ -7,7 +7,7 @@ export const doc = {
7
7
  name: 'Bottom Sheet Switcher — Review flow',
8
8
  displayName: 'Bottom Sheet Switcher — Review flow',
9
9
  description:
10
- 'A two-step form flow that lets a person review settings, confirm them, or move back without replacing the shared dialog.',
10
+ 'A two-step form flow that lets a person review settings, confirm them, or move back, each step in its own native dialog under one scrim.',
11
11
  isReady: true,
12
12
  isShowcase: false,
13
13
  aspectRatio: 3 / 4,
@@ -7,7 +7,7 @@ export const doc = {
7
7
  name: 'Bottom Sheet Switcher',
8
8
  displayName: 'Bottom Sheet Switcher',
9
9
  description:
10
- 'A three-step flow that transitions between content-hugging sheets of different heights inside one shared dialog.',
10
+ 'A three-step flow that transitions between content-hugging sheets of different heights, each step in its own native dialog with one scrim handed between them.',
11
11
  isReady: true,
12
12
  isShowcase: true,
13
13
  aspectRatio: 3 / 4,
@@ -488,7 +488,7 @@ export function registerDiscover(program) {
488
488
  : detail === 'compact'
489
489
  ? formatCompact(docs, docs.name, '')
490
490
  : formatFull(docs);
491
- emit(code(md));
491
+ emit(record({package: result.package}), code(md));
492
492
  break;
493
493
  }
494
494
 
@@ -154,6 +154,7 @@ describe('astryx discover with a discover source', () => {
154
154
  expect(meta.available.slice(official.length)).toEqual([
155
155
  {
156
156
  name: '@test/charts',
157
+ package: '@test/charts',
157
158
  components: ['Chart'],
158
159
  version: '2.0.0',
159
160
  templates: ['pages/Report'],
@@ -162,6 +163,7 @@ describe('astryx discover with a discover source', () => {
162
163
  },
163
164
  {
164
165
  name: '@test/boards',
166
+ package: '@test/boards',
165
167
  components: [],
166
168
  version: '1.0.0',
167
169
  templates: ['pages/DialBoard'],
@@ -269,6 +271,10 @@ describe('astryx discover with a discover source', () => {
269
271
  cwd: project,
270
272
  });
271
273
  expect(JSON.parse(opened.stdout).type).toBe('discover.detail.doc');
274
+
275
+ // Text mode names the package on stdout, so a pipe keeps it.
276
+ const text = await runCli(['discover', '@test/kit/Dial'], {cwd: project});
277
+ expect(text.stdout).toMatch(/package: @test\/kit/);
272
278
  });
273
279
 
274
280
  it('saves the answer in the user cache and writes nothing into the project', async () => {
@@ -117,22 +117,22 @@ export const doc = {
117
117
  {
118
118
  value: 'discover.list',
119
119
  description:
120
- 'What the project has, the integrations it loads and the official packages it declares, official packages first (name, category, components, version, a list per other kind they add, and latest when a source knows it); meta.available lists what the project could add, the official packages first, each with the command that adds it, and meta.sources reports each source, the official list last; when it lists no integration it carries meta.configured to tell "nothing configured" from "nothing discovered".',
120
+ 'What the project has, the integrations it loads and the official packages it declares, official packages first (package, the npm package and always equal to name; name, category, components, version, a list per other kind they add, and latest when a source knows it); meta.available lists what the project could add, the official packages first, each with its package and the command that adds it, and meta.sources reports each source, the official list last; when it lists no integration it carries meta.configured to tell "nothing configured" from "nothing discovered".',
121
121
  },
122
122
  {
123
123
  value: 'discover.detail',
124
124
  description:
125
- 'One package, for an @scope/name or @scope/name@version query: what the shown version adds, whether the project has it, and, when a source knows the package, its versions, latest release, and the command that adds it.',
125
+ 'One package, for an @scope/name or @scope/name@version query: its package (the npm package the result is about), what the shown version adds, whether the project has it, and, when a source knows the package, its versions, latest release, and the command that adds it.',
126
126
  },
127
127
  {
128
128
  value: 'discover.detail.doc',
129
129
  description:
130
- 'The validated ComponentDoc for one installed component, for an @scope/name/Component query.',
130
+ 'The validated ComponentDoc for one installed component, for an @scope/name/Component query, plus package, the npm package that owns the component.',
131
131
  },
132
132
  {
133
133
  value: 'discover.item',
134
134
  description:
135
- 'One item that is not an installed component, for an @scope/name/<item> query: its kind, name, package, version, and whether the project has the package.',
135
+ 'One item that is not an installed component, for an @scope/name/<item> query: its kind, name, package, version, and whether the project has the package. The envelope\'s package names the same package.',
136
136
  },
137
137
  {
138
138
  value: 'discover.search',
@@ -272,7 +272,7 @@ export const doc = {
272
272
  {
273
273
  value: 'theme.palette.generate',
274
274
  description:
275
- 'An author-reviewable OKLCH palette candidate, its reproducibility receipt, summary counts, and optional candidate/receipt file-write result.',
275
+ 'An author-reviewable OKLCH palette response: recipe (`astryx-oklch-v1`), status (`candidate`), familyCount, stopCount, modes, candidate (`TonalPaletteCandidate`), and generationReceipt. The generationReceipt contains schemaVersion (1), recipe, generatorVersion (`palette-generator-v1`), candidateFormatVersion (`palette-typescript-v1` or `palette-json-v1`), candidateSha256, optional preview, resolved request, and diagnostics. File-write fields are output, receipt, preview, written, and reason (`exists` or null).',
276
276
  },
277
277
 
278
278
  // upgrade
@@ -172,6 +172,35 @@ describe('response-types EnumDoc names every field', () => {
172
172
  expectNamed('theme.targets', fieldsOf(res.data));
173
173
  });
174
174
 
175
+ it('theme.palette.generate, including receipt provenance', async () => {
176
+ const cwd = fs.mkdtempSync(
177
+ path.join(os.tmpdir(), 'astryx-response-types-palette-'),
178
+ );
179
+ fs.writeFileSync(
180
+ path.join(cwd, 'palette.config.json'),
181
+ JSON.stringify({
182
+ modeStrategy: 'light-only',
183
+ stops: [20, 50, 80],
184
+ families: [{id: 'blue', seed: '#0074e2'}],
185
+ }),
186
+ );
187
+ const res = await data(
188
+ ['theme', 'palette', 'generate', 'palette.config.json'],
189
+ cwd,
190
+ );
191
+ expect(res.type).toBe('theme.palette.generate');
192
+ expectNamed('theme.palette.generate', [
193
+ ...Object.keys(res.data),
194
+ ...Object.keys(res.data.generationReceipt),
195
+ ]);
196
+ expect(describedAs('theme.palette.generate')).toMatch(
197
+ /generatorVersion.*palette-generator-v1/,
198
+ );
199
+ expect(describedAs('theme.palette.generate')).toMatch(
200
+ /candidateFormatVersion.*palette-typescript-v1.*palette-json-v1/,
201
+ );
202
+ });
203
+
175
204
  it('gap-report.file, including each delivery', async () => {
176
205
  const res = await data([
177
206
  'gap-report',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.3",
3
+ "version": "0.7.4-canary.b25f95e",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -106,10 +106,10 @@
106
106
  "zod": "^4.4.3"
107
107
  },
108
108
  "peerDependencies": {
109
- "@astryxdesign/charts": "*",
110
- "@astryxdesign/core": "*",
111
- "@astryxdesign/lab": "*",
112
- "@astryxdesign/theme-neutral": "*"
109
+ "@astryxdesign/charts": "0.7.4-canary.b25f95e",
110
+ "@astryxdesign/core": "0.7.4-canary.b25f95e",
111
+ "@astryxdesign/lab": "0.7.4-canary.b25f95e",
112
+ "@astryxdesign/theme-neutral": "0.7.4-canary.b25f95e"
113
113
  },
114
114
  "peerDependenciesMeta": {
115
115
  "@astryxdesign/charts": {
@@ -126,10 +126,10 @@
126
126
  }
127
127
  },
128
128
  "devDependencies": {
129
- "@astryxdesign/charts": "*",
130
- "@astryxdesign/core": "*",
131
- "@astryxdesign/lab": "*",
132
- "@astryxdesign/theme-neutral": "*",
129
+ "@astryxdesign/charts": "0.7.4-canary.b25f95e",
130
+ "@astryxdesign/core": "0.7.4-canary.b25f95e",
131
+ "@astryxdesign/lab": "0.7.4-canary.b25f95e",
132
+ "@astryxdesign/theme-neutral": "0.7.4-canary.b25f95e",
133
133
  "@heroicons/react": "^2.2.0",
134
134
  "@stylexjs/stylex": "^0.19.0",
135
135
  "@types/babel__core": "^7.20.5",