@astryxdesign/cli 0.7.9-canary.10d2979 → 0.7.9-canary.159aceb

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.
@@ -35,7 +35,6 @@
35
35
  * "cable" is not "table".
36
36
  */
37
37
 
38
- import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
39
38
  import {
40
39
  stem,
41
40
  wordForms,
@@ -43,7 +42,7 @@ import {
43
42
  startsAWordOf,
44
43
  wordsOf,
45
44
  joined,
46
- isTypo,
45
+ typoDistance,
47
46
  } from './_words.mjs';
48
47
  import {pluralOf} from './_query.mjs';
49
48
 
@@ -224,8 +223,8 @@ export function scoreCandidate(
224
223
  consider(60, `name contains "${term}"`);
225
224
  }
226
225
  if (fuzzy) {
227
- const dist = levenshteinDistance(term, nameLower);
228
- if (isTypo(term, nameLower, dist)) {
226
+ const dist = typoDistance(term, nameLower);
227
+ if (dist != null) {
229
228
  consider(
230
229
  dist === 1 ? 80 : dist === 2 ? 40 : 20,
231
230
  `similar name (distance ${dist})`,
@@ -280,8 +279,8 @@ export function scoreCandidate(
280
279
  }
281
280
  if (startsAWordOf(term, kw)) consider(70, `keyword "${kw}"`);
282
281
  if (fuzzy) {
283
- const dist = levenshteinDistance(term, kwLower);
284
- if (isTypo(term, kwLower, dist) && dist <= 2) {
282
+ const dist = typoDistance(term, kwLower);
283
+ if (dist != null && dist <= 2) {
285
284
  consider(dist === 1 ? 70 : 30, `keyword "${kw}" (distance ${dist})`);
286
285
  }
287
286
  }
@@ -1,10 +1,6 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
- /**
5
- * @file Word matching for search: stems and word forms, word starts,
6
- * identifier spelling, joined names, and typo tolerance.
7
- */
8
4
  /**
9
5
  * Light stemmer: strips common English suffixes so "charts"/"charting" and
10
6
  * "chart" share a root. Deliberately crude (no Porter) — good enough to bridge
@@ -61,4 +57,14 @@ export function spellIdentifiers(query: string): string;
61
57
  * @returns {string}
62
58
  */
63
59
  export function joined(text: string): string;
60
+ /**
61
+ * The edit distance between two words when it counts as a typo (isTypo), or
62
+ * null. The shorter word's length caps the distance that can count. A pair
63
+ * the cap rules out needs no distance table, and the others compute only the
64
+ * cells within the cap.
65
+ * @param {string} a
66
+ * @param {string} b
67
+ * @returns {1 | 2 | 3 | null}
68
+ */
69
+ export function typoDistance(a: string, b: string): 1 | 2 | 3 | null;
64
70
  export function isTypo(a: string, b: string, dist: number): boolean;
@@ -5,6 +5,8 @@
5
5
  * identifier spelling, joined names, and typo tolerance.
6
6
  */
7
7
 
8
+ import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
9
+
8
10
  /**
9
11
  * Light stemmer: strips common English suffixes so "charts"/"charting" and
10
12
  * "chart" share a root. Deliberately crude (no Porter) — good enough to bridge
@@ -155,3 +157,27 @@ export const isTypo = (a, b, dist) =>
155
157
  dist <= 3 &&
156
158
  Math.min(a.length, b.length) >=
157
159
  TYPO_MIN_LENGTH[/** @type {1 | 2 | 3} */ (dist)];
160
+
161
+ /**
162
+ * The edit distance between two words when it counts as a typo (isTypo), or
163
+ * null. The shorter word's length caps the distance that can count. A pair
164
+ * the cap rules out needs no distance table, and the others compute only the
165
+ * cells within the cap.
166
+ * @param {string} a
167
+ * @param {string} b
168
+ * @returns {1 | 2 | 3 | null}
169
+ */
170
+ export function typoDistance(a, b) {
171
+ const shorter = Math.min(a.length, b.length);
172
+ const cap =
173
+ shorter >= TYPO_MIN_LENGTH[3]
174
+ ? 3
175
+ : shorter >= TYPO_MIN_LENGTH[2]
176
+ ? 2
177
+ : shorter >= TYPO_MIN_LENGTH[1]
178
+ ? 1
179
+ : 0;
180
+ if (cap === 0) return null;
181
+ const dist = levenshteinDistance(a, b, cap);
182
+ return dist >= 1 && dist <= cap ? /** @type {1 | 2 | 3} */ (dist) : null;
183
+ }
@@ -100,6 +100,10 @@
100
100
  "kind": "component",
101
101
  "name": "ChatUnreadDivider"
102
102
  },
103
+ {
104
+ "kind": "component",
105
+ "name": "CircleCheckIndicator"
106
+ },
103
107
  {
104
108
  "kind": "component",
105
109
  "name": "CircularProgress"
@@ -16,6 +16,9 @@
16
16
  /**
17
17
  * @param {string} a
18
18
  * @param {string} b
19
+ * @param {number} [max] - The largest distance the caller can use. When
20
+ * given, a larger distance answers `max + 1`, and only the cells within
21
+ * `max` of the diagonal are computed.
19
22
  * @returns {number}
20
23
  */
21
- export function levenshteinDistance(a: string, b: string): number;
24
+ export function levenshteinDistance(a: string, b: string, max?: number): number;
@@ -16,9 +16,13 @@
16
16
  /**
17
17
  * @param {string} a
18
18
  * @param {string} b
19
+ * @param {number} [max] - The largest distance the caller can use. When
20
+ * given, a larger distance answers `max + 1`, and only the cells within
21
+ * `max` of the diagonal are computed.
19
22
  * @returns {number}
20
23
  */
21
- export function levenshteinDistance(a, b) {
24
+ export function levenshteinDistance(a, b, max) {
25
+ if (max !== undefined) return distanceWithin(a, b, max);
22
26
  const m = a.length, n = b.length;
23
27
  // Early exit: the distance is always ≥ |m − n|, so once the length gap
24
28
  // exceeds the loosest fuzzy-match threshold any caller uses (the hook
@@ -39,3 +43,42 @@ export function levenshteinDistance(a, b) {
39
43
  }
40
44
  return dp[m][n];
41
45
  }
46
+
47
+ /**
48
+ * The edit distance between `a` and `b` when it is at most `max`, or
49
+ * `max + 1` when it is more. A path through a cell more than `max` from the
50
+ * diagonal costs more than `max`, so only that band is computed.
51
+ * @param {string} a
52
+ * @param {string} b
53
+ * @param {number} max
54
+ * @returns {number}
55
+ */
56
+ function distanceWithin(a, b, max) {
57
+ const over = max + 1;
58
+ if (Math.abs(a.length - b.length) > max) return over;
59
+ let previous = new Array(b.length + 1).fill(over);
60
+ let current = new Array(b.length + 1).fill(over);
61
+ for (let j = 0; j <= Math.min(b.length, max); j++) previous[j] = j;
62
+ for (let i = 1; i <= a.length; i++) {
63
+ current.fill(over);
64
+ const from = Math.max(1, i - max);
65
+ const to = Math.min(b.length, i + max);
66
+ if (i <= max) current[0] = i;
67
+ let rowMin = current[0];
68
+ for (let j = from; j <= to; j++) {
69
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
70
+ const value = Math.min(
71
+ previous[j - 1] + cost,
72
+ previous[j] + 1,
73
+ current[j - 1] + 1,
74
+ over,
75
+ );
76
+ current[j] = value;
77
+ if (value < rowMin) rowMin = value;
78
+ }
79
+ // Every later cell costs at least this row's least.
80
+ if (rowMin >= over) return over;
81
+ [previous, current] = [current, previous];
82
+ }
83
+ return Math.min(previous[b.length], over);
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.9-canary.10d2979",
3
+ "version": "0.7.9-canary.159aceb",
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",
@@ -124,10 +124,10 @@
124
124
  "zod": "^4.4.3"
125
125
  },
126
126
  "peerDependencies": {
127
- "@astryxdesign/charts": "0.7.9-canary.10d2979",
128
- "@astryxdesign/core": "0.7.9-canary.10d2979",
129
- "@astryxdesign/lab": "0.7.9-canary.10d2979",
130
- "@astryxdesign/theme-neutral": "0.7.9-canary.10d2979"
127
+ "@astryxdesign/charts": "0.7.9-canary.159aceb",
128
+ "@astryxdesign/core": "0.7.9-canary.159aceb",
129
+ "@astryxdesign/lab": "0.7.9-canary.159aceb",
130
+ "@astryxdesign/theme-neutral": "0.7.9-canary.159aceb"
131
131
  },
132
132
  "peerDependenciesMeta": {
133
133
  "@astryxdesign/charts": {
@@ -144,10 +144,10 @@
144
144
  }
145
145
  },
146
146
  "devDependencies": {
147
- "@astryxdesign/charts": "0.7.9-canary.10d2979",
148
- "@astryxdesign/core": "0.7.9-canary.10d2979",
149
- "@astryxdesign/lab": "0.7.9-canary.10d2979",
150
- "@astryxdesign/theme-neutral": "0.7.9-canary.10d2979",
147
+ "@astryxdesign/charts": "0.7.9-canary.159aceb",
148
+ "@astryxdesign/core": "0.7.9-canary.159aceb",
149
+ "@astryxdesign/lab": "0.7.9-canary.159aceb",
150
+ "@astryxdesign/theme-neutral": "0.7.9-canary.159aceb",
151
151
  "@heroicons/react": "^2.2.0",
152
152
  "@stylexjs/stylex": "^0.19.0",
153
153
  "@types/babel__core": "^7.20.5",