@astryxdesign/cli 0.1.0-canary.9745d0a → 0.1.0-canary.9c16d98
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/bin/astryx.mjs +7 -22
- package/docs/icons.doc.mjs +1 -1
- package/docs/migration.doc.mjs +2 -2
- package/docs/shape.doc.mjs +1 -1
- package/docs/styling.doc.mjs +2 -2
- package/docs/theme.doc.dense.mjs +2 -2
- package/docs/theme.doc.mjs +0 -14
- package/docs/theme.doc.zh.mjs +2 -2
- package/docs/working-with-ai.doc.mjs +3 -3
- package/package.json +8 -8
- package/src/api/search.mjs +13 -207
- package/src/api/template.mjs +1 -2
- package/src/codemods/__tests__/registry.test.mjs +0 -1
- package/src/codemods/registry.mjs +0 -1
- package/src/codemods/runner.mjs +51 -105
- package/src/commands/agent-docs.mjs +56 -92
- package/src/commands/agent-docs.path-safety.test.mjs +1 -1
- package/src/commands/agent-docs.test.mjs +10 -66
- package/src/commands/build-theme.import-path.test.mjs +1 -1
- package/src/commands/build-theme.path-safety.test.mjs +1 -1
- package/src/commands/build-theme.prose.test.mjs +1 -1
- package/src/commands/component-package.test.mjs +1 -1
- package/src/commands/component.test.mjs +1 -1
- package/src/commands/docs.test.mjs +1 -1
- package/src/commands/doctor.test.mjs +1 -1
- package/src/commands/external-showcase.test.mjs +1 -1
- package/src/commands/init.mjs +1 -9
- package/src/commands/interactive-guard.test.mjs +1 -1
- package/src/commands/json-contract.test.mjs +1 -1
- package/src/commands/swizzle-gap-safety.test.mjs +1 -1
- package/src/commands/swizzle.path-safety.test.mjs +1 -1
- package/src/commands/template.path-safety.test.mjs +1 -1
- package/src/commands/template.test.mjs +1 -1
- package/src/commands/upgrade.mjs +38 -117
- package/src/commands/upgrade.test.mjs +1 -1
- package/src/index.mjs +0 -1
- package/src/lib/config.mjs +0 -12
- package/src/lib/error-codes.mjs +0 -3
- package/src/types/error-codes.d.ts +0 -1
- package/src/utils/interactive.mjs +1 -1
- package/src/utils/interactive.test.mjs +0 -2
- package/src/utils/package-manager.test.mjs +1 -1
- package/src/utils/path-safety.test.mjs +1 -1
- package/src/utils/paths.test.mjs +8 -8
- package/src/utils/update-check.mjs +26 -4
- package/src/utils/update-check.test.mjs +64 -2
- package/src/codemods/transforms/v0.1.0/__tests__/migrate-xds-config-surfaces.test.mjs +0 -116
- package/src/codemods/transforms/v0.1.0/__tests__/migrate-xds-module-specifiers.test.mjs +0 -51
- package/src/codemods/transforms/v0.1.0/index.mjs +0 -28
- package/src/codemods/transforms/v0.1.0/migrate-xds-config-surfaces.mjs +0 -230
- package/src/codemods/transforms/v0.1.0/migrate-xds-module-specifiers.mjs +0 -84
- package/src/commands/build.mjs +0 -196
- package/src/lib/config.test.mjs +0 -42
package/bin/astryx.mjs
CHANGED
|
@@ -12,25 +12,10 @@
|
|
|
12
12
|
//
|
|
13
13
|
// `node-version.mjs` is intentionally dependency-free so it loads on the
|
|
14
14
|
// unsupported runtimes this guard protects against.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// specifiers from the symlink's directory (→ `node_modules/src/...`) rather
|
|
20
|
-
// than the real package — breaking bare `../src/...` imports with a cryptic
|
|
21
|
-
// ERR_MODULE_NOT_FOUND. realpath-ing `import.meta.url` makes these imports
|
|
22
|
-
// resolve correctly however the bin is invoked (symlink, copy, or Windows
|
|
23
|
-
// shim). Uses only built-ins, so the version gate below still runs first.
|
|
24
|
-
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
25
|
-
import {realpathSync} from 'node:fs';
|
|
26
|
-
import {dirname, join} from 'node:path';
|
|
27
|
-
|
|
28
|
-
const binDir = dirname(realpathSync(fileURLToPath(import.meta.url)));
|
|
29
|
-
const importSrc = rel =>
|
|
30
|
-
import(pathToFileURL(join(binDir, '..', 'src', rel)).href);
|
|
31
|
-
|
|
32
|
-
const {isNodeVersionSupported, unsupportedNodeMessage} =
|
|
33
|
-
await importSrc('lib/node-version.mjs');
|
|
15
|
+
import {
|
|
16
|
+
isNodeVersionSupported,
|
|
17
|
+
unsupportedNodeMessage,
|
|
18
|
+
} from '../src/lib/node-version.mjs';
|
|
34
19
|
|
|
35
20
|
if (!isNodeVersionSupported(process.versions.node)) {
|
|
36
21
|
const msg = unsupportedNodeMessage(process.versions.node);
|
|
@@ -54,9 +39,9 @@ if (!isNodeVersionSupported(process.versions.node)) {
|
|
|
54
39
|
|
|
55
40
|
// Imports that transitively load `styleText` must happen AFTER the gate above,
|
|
56
41
|
// so they are dynamically imported here rather than at the top of the module.
|
|
57
|
-
const {program} = await
|
|
58
|
-
const {isJsonMode, toErrorEnvelope} = await
|
|
59
|
-
const {handleCommanderError} = await
|
|
42
|
+
const {program} = await import('../src/index.mjs');
|
|
43
|
+
const {isJsonMode, toErrorEnvelope} = await import('../src/lib/json.mjs');
|
|
44
|
+
const {handleCommanderError} = await import('../src/lib/json-shim.mjs');
|
|
60
45
|
|
|
61
46
|
/**
|
|
62
47
|
* Top-level error boundary (contract guarantee #4): an uncaught throw must
|
package/docs/icons.doc.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file Icons reference doc: semantic icon names available in
|
|
4
|
+
* @file Icons reference doc: semantic icon names available in XDS
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/** @type {import('../../core/src/docs-types').ReferenceDoc} */
|
package/docs/migration.doc.mjs
CHANGED
|
@@ -234,7 +234,7 @@ export function AppRoot({children}: {children: React.ReactNode}) {
|
|
|
234
234
|
type: 'code',
|
|
235
235
|
lang: 'text',
|
|
236
236
|
label: 'Paste this into your AI',
|
|
237
|
-
code: `We are migrating this existing Tailwind/shadcn app to
|
|
237
|
+
code: `We are migrating this existing Tailwind/shadcn app to XDS incrementally.
|
|
238
238
|
|
|
239
239
|
First run:
|
|
240
240
|
- npx astryx docs migration --dense
|
|
@@ -242,7 +242,7 @@ First run:
|
|
|
242
242
|
- npx astryx docs styling --dense
|
|
243
243
|
- npx astryx template AppShellTopNavWithSideNav --skeleton
|
|
244
244
|
|
|
245
|
-
Then migrate one route or shell surface at a time. Keep business logic and routing intact. Replace shadcn/Radix/Tailwind primitives with
|
|
245
|
+
Then migrate one route or shell surface at a time. Keep business logic and routing intact. Replace shadcn/Radix/Tailwind primitives with XDS components, remove hardcoded colors, verify light and dark mode, and take screenshots before moving to the next surface.`,
|
|
246
246
|
},
|
|
247
247
|
],
|
|
248
248
|
},
|
package/docs/shape.doc.mjs
CHANGED
|
@@ -44,7 +44,7 @@ export const docs = {
|
|
|
44
44
|
type: 'code',
|
|
45
45
|
lang: 'css',
|
|
46
46
|
label: 'Concentric radius formula',
|
|
47
|
-
code: `/* Automatic in
|
|
47
|
+
code: `/* Automatic in XDS Card */
|
|
48
48
|
--card-concentric-radius: max(0px, calc(var(--_card-radius) - var(--card-padding)));`,
|
|
49
49
|
},
|
|
50
50
|
],
|
package/docs/styling.doc.mjs
CHANGED
|
@@ -231,7 +231,7 @@ const overrides = stylex.create({
|
|
|
231
231
|
content: [
|
|
232
232
|
{
|
|
233
233
|
type: 'prose',
|
|
234
|
-
text: 'When external CSS needs to target an
|
|
234
|
+
text: 'When external CSS needs to target an XDS component by prop or state, combine the stable component class with reflected data attributes. The component class identifies the component (`.astryx-button`, `.astryx-card`); data attributes identify the axis and value (`data-variant`, `data-size`, `data-level`, etc.). This is the preferred selector surface for new CSS because it is explicit and collision-resistant.',
|
|
235
235
|
},
|
|
236
236
|
{
|
|
237
237
|
type: 'code',
|
|
@@ -273,7 +273,7 @@ const overrides = stylex.create({
|
|
|
273
273
|
content: [
|
|
274
274
|
{
|
|
275
275
|
type: 'prose',
|
|
276
|
-
text: '
|
|
276
|
+
text: 'XDS still emits legacy bare prop/state classes such as `.primary`, `.sm`, `.level-2`, and `.checked` for compatibility with existing apps and built themes. Do not write new CSS against these bare classes. The stable base component classes (`.astryx-button`, `.astryx-card`, etc.) are not deprecated; only the unprefixed prop/state classes are the legacy surface.',
|
|
277
277
|
},
|
|
278
278
|
{
|
|
279
279
|
type: 'code',
|
package/docs/theme.doc.dense.mjs
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
export const docsDense = {
|
|
6
6
|
description: 'Theme provider, custom themes, light/dark, component overrides',
|
|
7
7
|
sections: [
|
|
8
|
-
{ title: 'Quick Start', content: [null, null,
|
|
9
|
-
{ title: 'Themes', content: [null,
|
|
8
|
+
{ title: 'Quick Start', content: [null, null, { type: 'prose', text: 'default import = runtime injection. /built import = pre-compiled CSS (pair with theme.css).' }] },
|
|
9
|
+
{ title: 'Themes', content: [null, { type: 'prose', text: 'published: neutral (start here), butter, chocolate, gothic (dark-only), matcha, stone, y2k. @astryxdesign/theme-{name} = source (runtime). @astryxdesign/theme-{name}/built = optimized (+ theme.css).' }] },
|
|
10
10
|
{ title: 'Props', content: [null] },
|
|
11
11
|
{ title: 'Custom Theme', content: [{ type: 'prose', text: 'CLI wizard or manual defineTheme. only override tokens that differ.' }, null] },
|
|
12
12
|
{ title: 'defineTheme', content: [{ type: 'prose', text: 'scale configs (color, typography, radius, motion) + explicit token overrides + component overrides. color derives full palette from accent hex via HCT.' }, null, null] },
|
package/docs/theme.doc.mjs
CHANGED
|
@@ -14,12 +14,6 @@ export const docs = {
|
|
|
14
14
|
title: 'Quick Start',
|
|
15
15
|
category: 'guide',
|
|
16
16
|
content: [
|
|
17
|
-
{
|
|
18
|
-
type: 'code',
|
|
19
|
-
lang: 'bash',
|
|
20
|
-
label: 'Install a theme package',
|
|
21
|
-
code: 'npm install @astryxdesign/theme-neutral',
|
|
22
|
-
},
|
|
23
17
|
{
|
|
24
18
|
type: 'code',
|
|
25
19
|
lang: 'tsx',
|
|
@@ -51,10 +45,6 @@ function App() {
|
|
|
51
45
|
);
|
|
52
46
|
}`,
|
|
53
47
|
},
|
|
54
|
-
{
|
|
55
|
-
type: 'prose',
|
|
56
|
-
text: 'Each theme ships as its own npm package. Install the one you want, then wrap your app in `<Theme>` — the same pattern works for every theme; just swap the package and import name.',
|
|
57
|
-
},
|
|
58
48
|
{
|
|
59
49
|
type: 'prose',
|
|
60
50
|
text: 'The default import uses runtime style injection, which works everywhere with no build step. The `/built` import skips injection and relies on the pre-compiled CSS file for better performance and SSR support.',
|
|
@@ -65,10 +55,6 @@ function App() {
|
|
|
65
55
|
title: 'Available Themes',
|
|
66
56
|
category: 'guide',
|
|
67
57
|
content: [
|
|
68
|
-
{
|
|
69
|
-
type: 'prose',
|
|
70
|
-
text: 'Install the theme package you want with `npm install @astryxdesign/theme-{name}`, then import its theme object as shown below.',
|
|
71
|
-
},
|
|
72
58
|
{
|
|
73
59
|
type: 'table',
|
|
74
60
|
headers: ['Theme', 'Import', 'Description'],
|
package/docs/theme.doc.zh.mjs
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
export const docsZh = {
|
|
6
6
|
description: 'Theme 提供者、自定义主题、亮/暗模式和组件样式覆盖。',
|
|
7
7
|
sections: [
|
|
8
|
-
{ title: '快速开始', content: [null, null,
|
|
9
|
-
{ title: '可用主题', content: [null,
|
|
8
|
+
{ title: '快速开始', content: [null, null, { type: 'prose', text: '默认导入使用运行时样式注入。/built 导入使用预编译 CSS(需配合 theme.css)。' }] },
|
|
9
|
+
{ title: '可用主题', content: [null, { type: 'prose', text: '已发布主题:neutral(推荐起点)、butter、chocolate、gothic(仅暗色)、matcha、stone、y2k。@astryxdesign/theme-{name} = 源码版(运行时注入)。@astryxdesign/theme-{name}/built = 优化版(配合 theme.css)。' }] },
|
|
10
10
|
{ title: 'Theme 属性', content: [null] },
|
|
11
11
|
{ title: '创建自定义主题', content: [{ type: 'prose', text: '使用 CLI 向导(推荐)或手动 defineTheme。只覆盖与默认值不同的令牌。' }, null] },
|
|
12
12
|
{ title: 'defineTheme', content: [{ type: 'prose', text: '支持比例配置(typography、radius、motion)+ 显式令牌覆盖 + 组件覆盖。' }, null, null] },
|
|
@@ -34,7 +34,7 @@ export const docs = {
|
|
|
34
34
|
type: 'code',
|
|
35
35
|
lang: 'text',
|
|
36
36
|
label: 'Paste this into your AI',
|
|
37
|
-
code: 'Install @astryxdesign/cli and run `npx astryx agent-docs` to set up your
|
|
37
|
+
code: 'Install @astryxdesign/cli and run `npx astryx agent-docs` to set up your XDS context. Read the generated file.',
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
type: 'prose',
|
|
@@ -103,7 +103,7 @@ npx astryx agent-docs --agent-docs-path ~/.cursor/rules/xds.mdc`,
|
|
|
103
103
|
type: 'code',
|
|
104
104
|
lang: 'text',
|
|
105
105
|
label: 'Paste this into your AI',
|
|
106
|
-
code: `Before writing any
|
|
106
|
+
code: `Before writing any XDS code, check your knowledge:
|
|
107
107
|
|
|
108
108
|
1. What is the correct import path for Button?
|
|
109
109
|
2. How do you make an Dialog non-dismissible?
|
|
@@ -165,7 +165,7 @@ npx astryx docs tokens --dense`,
|
|
|
165
165
|
content: [
|
|
166
166
|
{
|
|
167
167
|
type: 'prose',
|
|
168
|
-
text: '
|
|
168
|
+
text: 'XDS ships a Model Context Protocol (MCP) server that any MCP-compatible AI tool can connect to. Instead of manually pasting CLI output, the AI can query the XDS design system directly, searching for components, reading full documentation, and pulling code examples on demand.',
|
|
169
169
|
},
|
|
170
170
|
{
|
|
171
171
|
type: 'prose',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.1.0-canary.
|
|
3
|
+
"version": "0.1.0-canary.9c16d98",
|
|
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",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"url": "https://github.com/facebook/astryx/issues"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [
|
|
18
|
-
"
|
|
18
|
+
"xds",
|
|
19
19
|
"cli",
|
|
20
20
|
"design-system",
|
|
21
21
|
"init",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"jscodeshift": "^17.3.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@astryxdesign/core": "0.1.0-canary.
|
|
58
|
-
"@astryxdesign/lab": "0.1.0-canary.
|
|
59
|
-
"@astryxdesign/theme-neutral": "0.1.0-canary.
|
|
57
|
+
"@astryxdesign/core": "0.1.0-canary.9c16d98",
|
|
58
|
+
"@astryxdesign/lab": "0.1.0-canary.9c16d98",
|
|
59
|
+
"@astryxdesign/theme-neutral": "0.1.0-canary.9c16d98"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
|
62
62
|
"@astryxdesign/core": {
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@astryxdesign/core": "0.1.0-canary.
|
|
74
|
-
"@astryxdesign/lab": "0.1.0-canary.
|
|
75
|
-
"@astryxdesign/theme-neutral": "0.1.0-canary.
|
|
73
|
+
"@astryxdesign/core": "0.1.0-canary.9c16d98",
|
|
74
|
+
"@astryxdesign/lab": "0.1.0-canary.9c16d98",
|
|
75
|
+
"@astryxdesign/theme-neutral": "0.1.0-canary.9c16d98"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"astryx": "node bin/astryx.mjs",
|
package/src/api/search.mjs
CHANGED
|
@@ -41,184 +41,14 @@ import {
|
|
|
41
41
|
} from '../lib/component-discovery.mjs';
|
|
42
42
|
import {discoverHooks, findHookDoc} from '../lib/hook-discovery.mjs';
|
|
43
43
|
import {levenshteinDistance} from '../lib/string-utils.mjs';
|
|
44
|
-
import {discoverTemplates
|
|
44
|
+
import {discoverTemplates} from './template.mjs';
|
|
45
45
|
import {AstryxError} from './error.mjs';
|
|
46
46
|
|
|
47
47
|
const DOCS_DIR = path.join(CLI_ROOT, 'docs');
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* Synonym / intent map: product-language terms an agent is likely to type,
|
|
51
|
-
* expanded to the catalog's vocabulary so oblique queries still rank. Keys and
|
|
52
|
-
* values are matched bidirectionally (typing any value also pulls in the key
|
|
53
|
-
* and its siblings). Lowercase, single words or short phrases.
|
|
54
|
-
*/
|
|
55
|
-
const SYNONYMS = {
|
|
56
|
-
dashboard: ['overview', 'analytics', 'kpi', 'kpis', 'metrics', 'stats', 'reporting', 'insights', 'control'],
|
|
57
|
-
login: ['signin', 'auth', 'authentication', 'sso', 'credentials', 'account'],
|
|
58
|
-
signup: ['register', 'registration', 'onboarding'],
|
|
59
|
-
payment: ['checkout', 'billing', 'card', 'pay', 'purchase', 'order'],
|
|
60
|
-
pricing: ['plans', 'plan', 'tiers', 'tier', 'subscription', 'subscriptions'],
|
|
61
|
-
chat: ['messaging', 'message', 'messages', 'conversation', 'inbox', 'dm'],
|
|
62
|
-
settings: ['preferences', 'config', 'configuration', 'account'],
|
|
63
|
-
calendar: ['schedule', 'scheduling', 'events', 'event', 'month', 'agenda'],
|
|
64
|
-
table: ['list', 'rows', 'records', 'grid', 'spreadsheet', 'datatable'],
|
|
65
|
-
gallery: ['photos', 'photo', 'images', 'image', 'pictures'],
|
|
66
|
-
hero: ['banner', 'splash', 'headline', 'landing'],
|
|
67
|
-
form: ['fields', 'input', 'inputs', 'survey'],
|
|
68
|
-
profile: ['bio', 'avatar', 'user'],
|
|
69
|
-
documentation: ['docs', 'reference', 'guide', 'api'],
|
|
70
|
-
navigation: ['nav', 'menu', 'sidebar'],
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Flatten into a token -> Set(expansions) lookup (bidirectional).
|
|
74
|
-
const SYNONYM_INDEX = (() => {
|
|
75
|
-
const idx = new Map();
|
|
76
|
-
const add = (a, b) => {
|
|
77
|
-
if (!idx.has(a)) idx.set(a, new Set());
|
|
78
|
-
idx.get(a).add(b);
|
|
79
|
-
};
|
|
80
|
-
for (const [key, vals] of Object.entries(SYNONYMS)) {
|
|
81
|
-
for (const v of vals) {
|
|
82
|
-
add(key, v);
|
|
83
|
-
add(v, key);
|
|
84
|
-
for (const v2 of vals) if (v2 !== v) add(v, v2);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return idx;
|
|
88
|
-
})();
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Light stemmer: strips common English suffixes so "charts"/"charting" and
|
|
92
|
-
* "chart" share a root. Deliberately crude (no Porter) — good enough to bridge
|
|
93
|
-
* plural/gerund gaps without a dependency.
|
|
94
|
-
* @param {string} w
|
|
95
|
-
* @returns {string}
|
|
96
|
-
*/
|
|
97
|
-
export function stem(w) {
|
|
98
|
-
let s = w;
|
|
99
|
-
for (const suf of ['ing', 'ed', 'ies', 'es', 's']) {
|
|
100
|
-
if (s.length > suf.length + 2 && s.endsWith(suf)) {
|
|
101
|
-
s = suf === 'ies' ? s.slice(0, -3) + 'y' : s.slice(0, -suf.length);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return s;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
49
|
/** Valid domain filters for `--type`. */
|
|
110
50
|
export const SEARCH_DOMAINS = ['component', 'hook', 'doc', 'template'];
|
|
111
51
|
|
|
112
|
-
/**
|
|
113
|
-
* Filler words stripped from multi-word queries so natural-language phrasing
|
|
114
|
-
* ("a page where you can see business stats") ranks on its content words.
|
|
115
|
-
*/
|
|
116
|
-
const STOPWORDS = new Set([
|
|
117
|
-
'a', 'an', 'the', 'of', 'for', 'to', 'with', 'and', 'or', 'in', 'on', 'at',
|
|
118
|
-
'by', 'that', 'this', 'my', 'your', 'our', 'their', 'is', 'are', 'be', 'it',
|
|
119
|
-
'its', 'as', 'from', 'page', 'screen', 'app', 'application', 'view', 'where',
|
|
120
|
-
'you', 'can', 'some', 'like', 'just', 'basically', 'kinda', 'want', 'wants',
|
|
121
|
-
'need', 'needs', 'something', 'thing', 'things', 'build', 'make', 'create',
|
|
122
|
-
'i', 'me', 'we', 'us', 'so', 'up', 'out', 'over', 'side', 'one', 'big',
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Split a query into meaningful content tokens (lowercased, stopwords + very
|
|
127
|
-
* short words removed). Empty for single-word queries (callers fall back to
|
|
128
|
-
* whole-phrase scoring).
|
|
129
|
-
* @param {string} term - Already-lowercased query.
|
|
130
|
-
* @returns {string[]}
|
|
131
|
-
*/
|
|
132
|
-
export function tokenizeQuery(term) {
|
|
133
|
-
return term
|
|
134
|
-
.split(/\s+/)
|
|
135
|
-
// Strip only leading/trailing punctuation; keep joined identifiers intact
|
|
136
|
-
// (e.g. "foo_bar" stays one token) so gibberish stays gibberish.
|
|
137
|
-
.map(t => t.replace(/^[^a-z0-9]+|[^a-z0-9]+$/g, ''))
|
|
138
|
-
.filter(t => t.length >= 2 && !STOPWORDS.has(t));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Score a candidate against a query, handling multi-word natural language.
|
|
143
|
-
* Tries the whole phrase (so exact/near matches still win) AND a per-token
|
|
144
|
-
* pass (so "data table with filters" matches `table-page` via table+filter),
|
|
145
|
-
* and returns whichever is stronger.
|
|
146
|
-
*
|
|
147
|
-
* @param {string} term - Lowercased full query.
|
|
148
|
-
* @param {string[]} tokens - Content tokens from tokenizeQuery(term).
|
|
149
|
-
* @param {object} candidate
|
|
150
|
-
* @returns {{score: number, reason: string} | null}
|
|
151
|
-
*/
|
|
152
|
-
/**
|
|
153
|
-
* Minimum per-token score (in the multi-word pass) to count as a real match.
|
|
154
|
-
* 50 = a genuine name/keyword/description hit; below that is loose Levenshtein
|
|
155
|
-
* fuzz that would otherwise turn gibberish queries into noise.
|
|
156
|
-
*/
|
|
157
|
-
const MIN_TOKEN_SCORE = 50;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Best score for a token against a candidate, fanning out through synonyms
|
|
161
|
-
* (synonym hits are discounted so a direct hit always wins).
|
|
162
|
-
* @returns {{score: number, reason: string} | null}
|
|
163
|
-
*/
|
|
164
|
-
function bestForToken(tok, candidate) {
|
|
165
|
-
let best = scoreCandidate(tok, candidate);
|
|
166
|
-
const syns = SYNONYM_INDEX.get(tok);
|
|
167
|
-
if (syns) {
|
|
168
|
-
for (const s of syns) {
|
|
169
|
-
const h = scoreCandidate(s, candidate);
|
|
170
|
-
if (h) {
|
|
171
|
-
const score = Math.round(h.score * 0.85);
|
|
172
|
-
if (!best || score > best.score) best = {score, reason: `${h.reason} (~${tok})`};
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return best;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function scoreQuery(term, tokens, candidate) {
|
|
180
|
-
const full = scoreCandidate(term, candidate);
|
|
181
|
-
|
|
182
|
-
// 0–1 content tokens: keep whole-phrase fuzzy matching (typo tolerance for
|
|
183
|
-
// single words), but if stopwords left exactly one DIFFERENT token (e.g.
|
|
184
|
-
// "pricing page" → "pricing"), score that token too and take the stronger.
|
|
185
|
-
if (tokens.length <= 1) {
|
|
186
|
-
const single = tokens.length === 1 ? bestForToken(tokens[0], candidate) : null;
|
|
187
|
-
if (full && (!single || full.score >= single.score)) return full;
|
|
188
|
-
return single;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Multi-word natural language: score each content token, counting only
|
|
192
|
-
// strong hits, then reward coverage so candidates matching more terms win.
|
|
193
|
-
let sum = 0;
|
|
194
|
-
let matched = 0;
|
|
195
|
-
const hitTerms = [];
|
|
196
|
-
for (const tok of tokens) {
|
|
197
|
-
const h = bestForToken(tok, candidate);
|
|
198
|
-
if (h && h.score >= MIN_TOKEN_SCORE) {
|
|
199
|
-
sum += h.score;
|
|
200
|
-
matched++;
|
|
201
|
-
hitTerms.push(tok);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (matched === 0) return full;
|
|
205
|
-
|
|
206
|
-
// Reward the AVERAGE strength of the concepts that matched (not divided by
|
|
207
|
-
// total query length — that penalizes verbose / low-fidelity prompts), plus
|
|
208
|
-
// a bonus per additional matched concept and a coverage term. A candidate
|
|
209
|
-
// that matches several of the query's concepts beats one matching a single
|
|
210
|
-
// incidental word.
|
|
211
|
-
const avgMatched = sum / matched;
|
|
212
|
-
const coverage = matched / tokens.length;
|
|
213
|
-
const tokenScore = Math.round(avgMatched + Math.min(matched - 1, 3) * 12 + coverage * 15);
|
|
214
|
-
|
|
215
|
-
if (full && full.score >= tokenScore) return full;
|
|
216
|
-
return {
|
|
217
|
-
score: tokenScore,
|
|
218
|
-
reason: `matches ${matched}/${tokens.length} terms: ${hitTerms.join(', ')}`,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
52
|
/**
|
|
223
53
|
* Score a single candidate against the search term across name, keywords,
|
|
224
54
|
* and prose signals. Returns the best (highest) score plus a human reason,
|
|
@@ -277,13 +107,10 @@ export function scoreCandidate(term, {name, keywords = [], description = '', pro
|
|
|
277
107
|
else if (dist === 2) consider(30, `keyword "${kw}" (distance ${dist})`);
|
|
278
108
|
}
|
|
279
109
|
|
|
280
|
-
// ── Prose / description signals (
|
|
281
|
-
// Match the term's stem as a whole word, tolerating plural/gerund suffixes
|
|
282
|
-
// so "chart" matches "charts" and "filter" matches "filtering".
|
|
110
|
+
// ── Prose / description signals (whole-word boundary) ───────────
|
|
283
111
|
if (term.length >= 3) {
|
|
284
|
-
const
|
|
285
|
-
const
|
|
286
|
-
const re = new RegExp(`\\b${escaped}(s|es|ing|ed|ies)?\\b`);
|
|
112
|
+
const escaped = term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
113
|
+
const re = new RegExp(`\\b${escaped}\\b`);
|
|
287
114
|
if (description && re.test(description.toLowerCase())) {
|
|
288
115
|
consider(50, `description mentions "${term}"`);
|
|
289
116
|
} else {
|
|
@@ -413,30 +240,14 @@ async function gatherTemplates(cwd) {
|
|
|
413
240
|
} catch {
|
|
414
241
|
return [];
|
|
415
242
|
}
|
|
416
|
-
return templates.map(t => {
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
keywords = keywords.concat(extractComponents(t.filePath));
|
|
425
|
-
} catch {
|
|
426
|
-
// Best-effort: skip keyword enrichment if the source can't be read.
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
if (t.category) keywords = keywords.concat(t.category.split(/[^A-Za-z0-9]+/).filter(Boolean));
|
|
430
|
-
}
|
|
431
|
-
return {
|
|
432
|
-
domain: 'template',
|
|
433
|
-
name: t.dirName,
|
|
434
|
-
keywords,
|
|
435
|
-
description: t.description || '',
|
|
436
|
-
_displayName: t.name,
|
|
437
|
-
_kind: t.type, // 'page' | 'block'
|
|
438
|
-
};
|
|
439
|
-
});
|
|
243
|
+
return templates.map(t => ({
|
|
244
|
+
domain: 'template',
|
|
245
|
+
name: t.dirName,
|
|
246
|
+
keywords: Array.isArray(t.componentsUsed) ? t.componentsUsed : [],
|
|
247
|
+
description: t.description || '',
|
|
248
|
+
_displayName: t.name,
|
|
249
|
+
_kind: t.type, // 'page' | 'block'
|
|
250
|
+
}));
|
|
440
251
|
}
|
|
441
252
|
|
|
442
253
|
/**
|
|
@@ -514,7 +325,6 @@ export async function search(query, options = {}) {
|
|
|
514
325
|
}
|
|
515
326
|
|
|
516
327
|
const term = String(query).trim().toLowerCase();
|
|
517
|
-
const tokens = tokenizeQuery(term);
|
|
518
328
|
|
|
519
329
|
const coreDir = findCoreDir(cwd);
|
|
520
330
|
if (!coreDir) {
|
|
@@ -532,13 +342,9 @@ export async function search(query, options = {}) {
|
|
|
532
342
|
|
|
533
343
|
const all = [...components, ...hooks, ...docTopics, ...templates];
|
|
534
344
|
|
|
535
|
-
// Score every candidate on its own merits. The consumer groups results by
|
|
536
|
-
// role (page / block / component) and takes the top of each, so there's no
|
|
537
|
-
// cross-role competition to engineer — a target page only needs to be the
|
|
538
|
-
// strongest PAGE, not outrank every component.
|
|
539
345
|
const scored = [];
|
|
540
346
|
for (const candidate of all) {
|
|
541
|
-
const hit =
|
|
347
|
+
const hit = scoreCandidate(term, candidate);
|
|
542
348
|
if (hit) scored.push(toResult(candidate, hit.score, hit.reason));
|
|
543
349
|
}
|
|
544
350
|
|
package/src/api/template.mjs
CHANGED
|
@@ -95,7 +95,6 @@ async function discoverPages() {
|
|
|
95
95
|
dirName: dir.name,
|
|
96
96
|
name: doc?.name || dir.name,
|
|
97
97
|
description: doc?.description || '',
|
|
98
|
-
category: doc?.category || '',
|
|
99
98
|
isReady: doc?.isReady ?? true,
|
|
100
99
|
scaffold: doc?.scaffold ?? false,
|
|
101
100
|
filePath: path.join(dirPath, 'page.tsx'),
|
|
@@ -246,7 +245,7 @@ const UBIQUITOUS = new Set([
|
|
|
246
245
|
'StackItem', 'Icon',
|
|
247
246
|
]);
|
|
248
247
|
|
|
249
|
-
|
|
248
|
+
function extractComponents(pagePath) {
|
|
250
249
|
const src = fs.readFileSync(pagePath, 'utf-8');
|
|
251
250
|
// Match JSX opening tags, e.g. `<Section` or the legacy `<XDSSection`.
|
|
252
251
|
// Templates author bare component names post un-prefix migration
|
|
@@ -17,7 +17,6 @@ const registry = new Map([
|
|
|
17
17
|
['0.0.13', () => import('./transforms/v0.0.13/index.mjs')],
|
|
18
18
|
['0.0.14', () => import('./transforms/v0.0.14/index.mjs')],
|
|
19
19
|
['0.0.15', () => import('./transforms/v0.0.15/index.mjs')],
|
|
20
|
-
['0.1.0', () => import('./transforms/v0.1.0/index.mjs')],
|
|
21
20
|
]);
|
|
22
21
|
|
|
23
22
|
// Re-export from the shared utility so registry callers and other consumers
|