@astryxdesign/cli 0.7.3-canary.7370328 → 0.7.3-canary.813c1d5
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.
- package/README.md +1 -1
- package/api/build/kit/weights.d.mts +8 -22
- package/api/build/kit/weights.mjs +87 -8
- package/api/build/kit/weights.test.mjs +96 -0
- package/api/theme/palette/generate/generate.d.mts +8 -0
- package/api/theme/palette/generate/generate.mjs +38 -11
- package/api/theme/palette/generate/generate.test.mjs +83 -4
- package/api/theme/palette/generate/generator.d.mts +6 -0
- package/api/theme/palette/generate/generator.mjs +6 -0
- package/api/theme/theme.type.d.mts +12 -1
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/response/response-types.doc.test.mjs +29 -0
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -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,
|
|
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. |
|
|
@@ -18,36 +18,16 @@ export function weightWords(idea: string): string[];
|
|
|
18
18
|
* @param {string} idea
|
|
19
19
|
* @param {import('./rank.mjs').RankedPage[]} ranked the ranker's output for the idea
|
|
20
20
|
* @param {import('./rank.mjs').RankedPage | null} pick the ranker's own start
|
|
21
|
-
* @param {
|
|
21
|
+
* @param {DescribedTemplate[]} catalog the project's ready page templates
|
|
22
22
|
* @param {{weights?: WeightsFile | null, newPage?: boolean}} [options]
|
|
23
23
|
* `newPage`: the idea asks for a new page (rank.mjs `asksForNewPage`)
|
|
24
24
|
* @returns {string | null | undefined} a template id, null for the app shell,
|
|
25
25
|
* undefined without weights
|
|
26
26
|
*/
|
|
27
|
-
export function weighStart(idea: string, ranked: import("./rank.mjs").RankedPage[], pick: import("./rank.mjs").RankedPage | null, catalog: {
|
|
28
|
-
name: string;
|
|
29
|
-
}[], { weights, newPage }?: {
|
|
27
|
+
export function weighStart(idea: string, ranked: import("./rank.mjs").RankedPage[], pick: import("./rank.mjs").RankedPage | null, catalog: DescribedTemplate[], { weights, newPage }?: {
|
|
30
28
|
weights?: WeightsFile | null;
|
|
31
29
|
newPage?: boolean;
|
|
32
30
|
}): string | null | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* @file Word weights for `build`'s START (spec:AST-048): a checked-in table of
|
|
35
|
-
* per-template word weights, blended with the page ranker's own scores, picks
|
|
36
|
-
* the template an idea starts from.
|
|
37
|
-
*
|
|
38
|
-
* @input An idea, the ranker's output for it (`rankPages`, `pickStart`), the
|
|
39
|
-
* project's ready page templates, and the weights (`weights.json` beside this
|
|
40
|
-
* file, read by the adapter): the candidates (the app shell as `SHELL`, then page template ids), one or more
|
|
41
|
-
* word tables (stemmed words, a bias per candidate, and one row of weights
|
|
42
|
-
* per word, a character per candidate) and the blend numbers.
|
|
43
|
-
* @output `weighStart(idea, ranked, pick, catalog)`: the template id to start
|
|
44
|
-
* from, null for the app shell, or undefined when no table is available, in
|
|
45
|
-
* which case the ranker's own pick stands.
|
|
46
|
-
* @position Beside rank.mjs (api/build/kit/); kit.mjs calls it for every
|
|
47
|
-
* whole page (a part or an edit follows the ranker's placement rules). The
|
|
48
|
-
* ranker's pick of a template the tables do not list stands, so a new
|
|
49
|
-
* template can start a build.
|
|
50
|
-
*/
|
|
51
31
|
/** The app shell, as one candidate. */
|
|
52
32
|
export const SHELL: "SHELL";
|
|
53
33
|
export type WeightTable = {
|
|
@@ -80,3 +60,9 @@ export type WeightsFile = {
|
|
|
80
60
|
*/
|
|
81
61
|
blend: number[];
|
|
82
62
|
};
|
|
63
|
+
export type DescribedTemplate = {
|
|
64
|
+
name: string;
|
|
65
|
+
displayName?: string | undefined;
|
|
66
|
+
category?: string | undefined;
|
|
67
|
+
keywords?: string[] | undefined;
|
|
68
|
+
};
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
* from, null for the app shell, or undefined when no table is available, in
|
|
15
15
|
* which case the ranker's own pick stands.
|
|
16
16
|
* @position Beside rank.mjs (api/build/kit/); kit.mjs calls it for every
|
|
17
|
-
* whole page (a part or an edit follows the ranker's placement rules).
|
|
18
|
-
*
|
|
19
|
-
* template can start a build.
|
|
17
|
+
* whole page (a part or an edit follows the ranker's placement rules). A
|
|
18
|
+
* template the tables do not list competes on its own descriptor's words
|
|
19
|
+
* (`ownWords`), so a new template can start a build.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
import {STOPWORDS} from '../../search/search.mjs';
|
|
23
|
+
|
|
22
24
|
/** The app shell, as one candidate. */
|
|
23
25
|
export const SHELL = 'SHELL';
|
|
24
26
|
const SHELL_FAMILY = 'Shell';
|
|
@@ -225,12 +227,65 @@ function memberFeatures(v) {
|
|
|
225
227
|
]);
|
|
226
228
|
}
|
|
227
229
|
|
|
230
|
+
/**
|
|
231
|
+
* @typedef {object} DescribedTemplate
|
|
232
|
+
* @property {string} name
|
|
233
|
+
* @property {string} [displayName]
|
|
234
|
+
* @property {string} [category]
|
|
235
|
+
* @property {string[]} [keywords]
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* How many of the idea's stemmed words a template's own descriptor names: its
|
|
240
|
+
* display name, its category, and its keywords, less search's stopwords.
|
|
241
|
+
* @param {string} name
|
|
242
|
+
* @param {DescribedTemplate[]} catalog
|
|
243
|
+
* @param {Set<string>} words the idea's stemmed words, less search's stopwords
|
|
244
|
+
*/
|
|
245
|
+
function ownWords(name, catalog, words) {
|
|
246
|
+
const t = catalog.find(c => c.name === name);
|
|
247
|
+
if (!t) return 0;
|
|
248
|
+
// Search's stopwords are no evidence: "to" in a "to-do list" keyword must
|
|
249
|
+
// not answer the "to" of "rows to track orders".
|
|
250
|
+
const own = new Set(
|
|
251
|
+
weightWords(
|
|
252
|
+
[t.displayName ?? '', t.category ?? '', ...(t.keywords ?? [])].join(' '),
|
|
253
|
+
)
|
|
254
|
+
.filter(w => !STOPWORDS.has(w))
|
|
255
|
+
.map(stem),
|
|
256
|
+
);
|
|
257
|
+
let n = 0;
|
|
258
|
+
for (const w of words) if (own.has(w)) n++;
|
|
259
|
+
return n;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** How many fewer own words a template whose family the idea names first may
|
|
263
|
+
* name than the listed template it competes with, and still start. */
|
|
264
|
+
const FAMILY_SLACK = 2;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Where the idea first names a template's family, the part of its category
|
|
268
|
+
* before ` - ` ("Dashboard" in "Dashboard - Analytics"): the index of that
|
|
269
|
+
* word among the idea's stemmed words, or Infinity when it does not.
|
|
270
|
+
* @param {string} name
|
|
271
|
+
* @param {DescribedTemplate[]} catalog
|
|
272
|
+
* @param {string[]} order the idea's stemmed words, in order
|
|
273
|
+
*/
|
|
274
|
+
function familyAt(name, catalog, order) {
|
|
275
|
+
const t = catalog.find(c => c.name === name);
|
|
276
|
+
const family = weightWords(String(t?.category ?? '').split(' - ')[0]).map(
|
|
277
|
+
stem,
|
|
278
|
+
);
|
|
279
|
+
const at = family.length ? order.findIndex(w => family.includes(w)) : -1;
|
|
280
|
+
return at < 0 ? Infinity : at;
|
|
281
|
+
}
|
|
282
|
+
|
|
228
283
|
/**
|
|
229
284
|
* Where an idea starts, by the blended weights.
|
|
230
285
|
* @param {string} idea
|
|
231
286
|
* @param {import('./rank.mjs').RankedPage[]} ranked the ranker's output for the idea
|
|
232
287
|
* @param {import('./rank.mjs').RankedPage | null} pick the ranker's own start
|
|
233
|
-
* @param {
|
|
288
|
+
* @param {DescribedTemplate[]} catalog the project's ready page templates
|
|
234
289
|
* @param {{weights?: WeightsFile | null, newPage?: boolean}} [options]
|
|
235
290
|
* `newPage`: the idea asks for a new page (rank.mjs `asksForNewPage`)
|
|
236
291
|
* @returns {string | null | undefined} a template id, null for the app shell,
|
|
@@ -292,10 +347,34 @@ export function weighStart(
|
|
|
292
347
|
pick && pick.family !== SHELL_FAMILY && cands.includes(pick.name)
|
|
293
348
|
? pick.name
|
|
294
349
|
: null;
|
|
295
|
-
//
|
|
296
|
-
|
|
297
|
-
//
|
|
298
|
-
|
|
350
|
+
// A template the ranker placed by its frame stays (spec:AST-048/FR3).
|
|
351
|
+
if (kept && pick?.containerMatched) return kept;
|
|
352
|
+
// The tables cannot judge a template they do not list (an integration's
|
|
353
|
+
// template, or one added since they were fit), so its own descriptor
|
|
354
|
+
// decides: the ranker's pick stands when the idea names as many words of its
|
|
355
|
+
// display name, category and keywords as of the tables' first listed
|
|
356
|
+
// template's, or names its family first and nearly as many; otherwise that
|
|
357
|
+
// listed template starts. Nothing learned about the template is involved,
|
|
358
|
+
// so a new template competes on its own words.
|
|
359
|
+
if (kept && !position.has(kept)) {
|
|
360
|
+
const listed = best(c => c !== SHELL && position.has(c));
|
|
361
|
+
if (!listed) return kept;
|
|
362
|
+
// The idea's own words, less search's stopwords: "basically" must not
|
|
363
|
+
// answer the "Basic" of a category.
|
|
364
|
+
const content = weightWords(idea).filter(w => !STOPWORDS.has(w));
|
|
365
|
+
const said = new Set(content.map(stem));
|
|
366
|
+
const mine = ownWords(kept, catalog, said);
|
|
367
|
+
const theirs = ownWords(listed, catalog, said);
|
|
368
|
+
if (mine >= theirs) return kept;
|
|
369
|
+
// An idea that names the template's family before the listed one's
|
|
370
|
+
// ("a dashboard with a data table") is that family's page, unless it
|
|
371
|
+
// names far more of the listed template's words.
|
|
372
|
+
const order = content.map(stem);
|
|
373
|
+
return familyAt(kept, catalog, order) < familyAt(listed, catalog, order) &&
|
|
374
|
+
mine >= theirs - FAMILY_SLACK
|
|
375
|
+
? kept
|
|
376
|
+
: listed;
|
|
377
|
+
}
|
|
299
378
|
const top = best(() => true);
|
|
300
379
|
if (top !== SHELL) return top;
|
|
301
380
|
// An idea that asks for a new page keeps the ranker's template rather than
|
|
@@ -125,6 +125,102 @@ describe('weighStart', () => {
|
|
|
125
125
|
expect(start).toBe('fresh');
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
+
describe('a template the tables do not list (cold start)', () => {
|
|
129
|
+
// A made-up family the tables have never seen, described only by its own
|
|
130
|
+
// descriptor, next to listed templates with descriptors of their own.
|
|
131
|
+
const catalog = [
|
|
132
|
+
{name: 'board', displayName: 'Kanban Board', keywords: ['kanban']},
|
|
133
|
+
{name: 'charts', displayName: 'Charts', category: 'Charts - Overview'},
|
|
134
|
+
{name: 'grid', displayName: 'Grid'},
|
|
135
|
+
{
|
|
136
|
+
name: 'gauge-fleet',
|
|
137
|
+
displayName: 'Fleet Gauges',
|
|
138
|
+
category: 'Gauges - Fleet',
|
|
139
|
+
keywords: ['gauges', 'fleet', 'meters'],
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
it('starts from it when the idea names its own words', () => {
|
|
144
|
+
const ranked = [page('gauge-fleet', 9, 'Gauges'), ...RANKED];
|
|
145
|
+
const start = weighStart(
|
|
146
|
+
'fleet gauges with meters per kanban lane',
|
|
147
|
+
ranked,
|
|
148
|
+
ranked[0],
|
|
149
|
+
catalog,
|
|
150
|
+
{weights: WEIGHTS},
|
|
151
|
+
);
|
|
152
|
+
expect(start).toBe('gauge-fleet');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('starts from it when the idea names its family first', () => {
|
|
156
|
+
const ranked = [page('gauge-fleet', 9, 'Gauges'), ...RANKED];
|
|
157
|
+
const start = weighStart(
|
|
158
|
+
'gauges page with a kanban board',
|
|
159
|
+
ranked,
|
|
160
|
+
ranked[0],
|
|
161
|
+
catalog,
|
|
162
|
+
{weights: WEIGHTS},
|
|
163
|
+
);
|
|
164
|
+
expect(start).toBe('gauge-fleet');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("never counts a stopword from another template's keywords", () => {
|
|
168
|
+
// "side" in grid's "side by side" keyword is one of search's stopwords;
|
|
169
|
+
// it must not answer the idea's "sides", which is not.
|
|
170
|
+
const own = [
|
|
171
|
+
{name: 'board'},
|
|
172
|
+
{name: 'charts'},
|
|
173
|
+
{
|
|
174
|
+
name: 'grid',
|
|
175
|
+
displayName: 'Grid',
|
|
176
|
+
keywords: ['side by side', 'orders'],
|
|
177
|
+
},
|
|
178
|
+
{name: 'fold', displayName: 'Folding Rows'},
|
|
179
|
+
];
|
|
180
|
+
const ranked = [page('fold', 9, 'Fold'), ...RANKED];
|
|
181
|
+
const start = weighStart(
|
|
182
|
+
'rows on two sides with orders on cards',
|
|
183
|
+
ranked,
|
|
184
|
+
ranked[0],
|
|
185
|
+
own,
|
|
186
|
+
{weights: WEIGHTS},
|
|
187
|
+
);
|
|
188
|
+
expect(start).toBe('fold');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("never counts a stopword from the idea's words", () => {
|
|
192
|
+
// "basically" is one of search's stopwords and stems to "basic", the
|
|
193
|
+
// word of grid's category; it must not tip the count to grid.
|
|
194
|
+
const own = [
|
|
195
|
+
{name: 'board'},
|
|
196
|
+
{name: 'charts'},
|
|
197
|
+
{name: 'grid', displayName: 'Grid', category: 'Grid - Basic'},
|
|
198
|
+
{name: 'fold', displayName: 'Folding Rows'},
|
|
199
|
+
];
|
|
200
|
+
const ranked = [page('fold', 9, 'Fold'), ...RANKED];
|
|
201
|
+
const start = weighStart(
|
|
202
|
+
'basically a grid of rows on cards',
|
|
203
|
+
ranked,
|
|
204
|
+
ranked[0],
|
|
205
|
+
own,
|
|
206
|
+
{weights: WEIGHTS},
|
|
207
|
+
);
|
|
208
|
+
expect(start).toBe('fold');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('yields to the listed template whose own words the idea names more', () => {
|
|
212
|
+
const ranked = [page('gauge-fleet', 9, 'Gauges'), ...RANKED];
|
|
213
|
+
const start = weighStart(
|
|
214
|
+
'a kanban board with a fleet column',
|
|
215
|
+
ranked,
|
|
216
|
+
ranked[0],
|
|
217
|
+
catalog,
|
|
218
|
+
{weights: WEIGHTS},
|
|
219
|
+
);
|
|
220
|
+
expect(start).toBe('board');
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
128
224
|
it("keeps the ranker's template for an idea that asks for a new page", () => {
|
|
129
225
|
const start = weighStart('the existing page', RANKED, RANKED[0], CATALOG, {
|
|
130
226
|
weights: WEIGHTS,
|
|
@@ -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
|
-
/**
|
|
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'))
|
|
96
|
-
|
|
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 {
|
|
105
|
-
function receiptFor(result,
|
|
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
|
-
|
|
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
|
|
375
|
+
let serialized = serializeCandidate(candidate, null);
|
|
349
376
|
const previewText = options.preview ? renderPalettePreview(candidate) : null;
|
|
350
|
-
let receipt = receiptFor(result,
|
|
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
|
-
|
|
367
|
-
receipt = receiptFor(result,
|
|
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:
|
|
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 {
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
/**
|
package/api/theme/theme.type.mjs
CHANGED
|
@@ -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 {
|
|
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,
|
|
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: [
|
|
@@ -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,
|
|
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-canary.
|
|
3
|
+
"version": "0.7.3-canary.813c1d5",
|
|
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": "0.7.3-canary.
|
|
110
|
-
"@astryxdesign/core": "0.7.3-canary.
|
|
111
|
-
"@astryxdesign/lab": "0.7.3-canary.
|
|
112
|
-
"@astryxdesign/theme-neutral": "0.7.3-canary.
|
|
109
|
+
"@astryxdesign/charts": "0.7.3-canary.813c1d5",
|
|
110
|
+
"@astryxdesign/core": "0.7.3-canary.813c1d5",
|
|
111
|
+
"@astryxdesign/lab": "0.7.3-canary.813c1d5",
|
|
112
|
+
"@astryxdesign/theme-neutral": "0.7.3-canary.813c1d5"
|
|
113
113
|
},
|
|
114
114
|
"peerDependenciesMeta": {
|
|
115
115
|
"@astryxdesign/charts": {
|
|
@@ -126,10 +126,10 @@
|
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
|
-
"@astryxdesign/charts": "0.7.3-canary.
|
|
130
|
-
"@astryxdesign/core": "0.7.3-canary.
|
|
131
|
-
"@astryxdesign/lab": "0.7.3-canary.
|
|
132
|
-
"@astryxdesign/theme-neutral": "0.7.3-canary.
|
|
129
|
+
"@astryxdesign/charts": "0.7.3-canary.813c1d5",
|
|
130
|
+
"@astryxdesign/core": "0.7.3-canary.813c1d5",
|
|
131
|
+
"@astryxdesign/lab": "0.7.3-canary.813c1d5",
|
|
132
|
+
"@astryxdesign/theme-neutral": "0.7.3-canary.813c1d5",
|
|
133
133
|
"@heroicons/react": "^2.2.0",
|
|
134
134
|
"@stylexjs/stylex": "^0.19.0",
|
|
135
135
|
"@types/babel__core": "^7.20.5",
|