@astryxdesign/cli 0.7.9-canary.6e2e242 → 0.7.9-canary.6fc2bff
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/api/search/_candidate-score.mjs +5 -6
- package/api/search/_words.d.mts +10 -4
- package/api/search/_words.mjs +26 -0
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.mjs +9 -4
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -1
- package/foundation/config/project.mjs +27 -9
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/text/levenshtein.d.mts +4 -1
- package/foundation/text/levenshtein.mjs +44 -1
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
|
@@ -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
|
-
|
|
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 =
|
|
228
|
-
if (
|
|
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 =
|
|
284
|
-
if (
|
|
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
|
}
|
package/api/search/_words.d.mts
CHANGED
|
@@ -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;
|
package/api/search/_words.mjs
CHANGED
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,16 @@
|
|
|
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
|
+
* Whether an executable `gh` is on `PATH` (with a `PATHEXT` extension on
|
|
6
|
+
* Windows), found without running it. The copy receipt offers its
|
|
7
|
+
* `gh issue create` line on it. Running `gh` would make every copy wait on a
|
|
8
|
+
* process start, and for `gh auth status` on GitHub, before it reports.
|
|
9
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
10
|
+
* @param {NodeJS.Platform} [platform]
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export function checkGhCli(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
4
14
|
/**
|
|
5
15
|
* The integration component that replaces the Core component `name`
|
|
6
16
|
* (spec:AST-035 FR11), or undefined when none does.
|
package/api/swizzle/_adapter.mjs
CHANGED
|
@@ -8,14 +8,37 @@
|
|
|
8
8
|
* of swizzlable components: `list` returns the names directly, `copy` uses them
|
|
9
9
|
* for its "component not found" suggestions. Resolving core + listing lives
|
|
10
10
|
* here once so neither leaf re-walks the filesystem. Throws AstryxError
|
|
11
|
-
* (ERR_CORE_NOT_FOUND) when core can't be located.
|
|
11
|
+
* (ERR_CORE_NOT_FOUND) when core can't be located. The copy receipt's `gh`
|
|
12
|
+
* lookup is here too, on the shared search-path walk.
|
|
12
13
|
*/
|
|
13
14
|
|
|
15
|
+
import {executablesOnSearchPath} from '../../foundation/env/search-path.mjs';
|
|
14
16
|
import {findProjectCoreDir, listComponents} from '../../foundation/fs/paths.mjs';
|
|
15
17
|
import {resolveComponentReplacements} from '../../foundation/discovery/component-replacement.mjs';
|
|
16
18
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
17
19
|
import {AstryxError} from '../error.mjs';
|
|
18
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Whether an executable `gh` is on `PATH` (with a `PATHEXT` extension on
|
|
23
|
+
* Windows), found without running it. The copy receipt offers its
|
|
24
|
+
* `gh issue create` line on it. Running `gh` would make every copy wait on a
|
|
25
|
+
* process start, and for `gh auth status` on GitHub, before it reports.
|
|
26
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
27
|
+
* @param {NodeJS.Platform} [platform]
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export function checkGhCli(env = process.env, platform = process.platform) {
|
|
31
|
+
const names =
|
|
32
|
+
platform === 'win32'
|
|
33
|
+
? (env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD')
|
|
34
|
+
.split(';')
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
.map(extension => `gh${extension.toLowerCase()}`)
|
|
37
|
+
: ['gh'];
|
|
38
|
+
const searchPath = env.PATH ?? env.Path ?? '';
|
|
39
|
+
return executablesOnSearchPath(names, {searchPath, platform}).length > 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
19
42
|
/** The package that owns Core's components, hooks, and codemods. */
|
|
20
43
|
export {CORE_PROVIDER_ID as CORE_PACKAGE} from '../../foundation/identity/providers.mjs';
|
|
21
44
|
|
|
@@ -15,9 +15,12 @@
|
|
|
15
15
|
|
|
16
16
|
import * as fs from 'node:fs';
|
|
17
17
|
import * as path from 'node:path';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
checkGhCli,
|
|
20
|
+
resolveComponentReplacement,
|
|
21
|
+
resolveCore,
|
|
22
|
+
} from '../_adapter.mjs';
|
|
19
23
|
import {assertWithin, sanitizeName, PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
|
|
20
|
-
import {checkGhCli} from '../_github.mjs';
|
|
21
24
|
import {Project} from '../../../foundation/config/project.mjs';
|
|
22
25
|
import {
|
|
23
26
|
CORE_PACKAGE,
|
|
@@ -299,6 +302,10 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
299
302
|
const outputBase = confineWrite(output, cwd, {label: 'output directory'});
|
|
300
303
|
const outputDir = path.join(outputBase, dirName);
|
|
301
304
|
|
|
305
|
+
// The receipt's feedback first: a swizzle that fails must fail before it
|
|
306
|
+
// writes anything.
|
|
307
|
+
const feedback = buildFeedback(dirName, owner.issuesUrl);
|
|
308
|
+
|
|
302
309
|
// Pre-flight path and overwrite checks before any mkdir/writeFile.
|
|
303
310
|
const sourceFiles = fs.readdirSync(componentDir).filter(file => {
|
|
304
311
|
if (isExcludedFromCopy(file)) return false;
|
|
@@ -380,8 +387,6 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
380
387
|
!isExcludedFromCopy(f) &&
|
|
381
388
|
fs.statSync(path.join(componentDir, f)).isFile(),
|
|
382
389
|
);
|
|
383
|
-
const feedback = buildFeedback(dirName, owner.issuesUrl);
|
|
384
|
-
|
|
385
390
|
/** @type {import('../swizzle.type.mjs').SwizzleCopyResponse['data']} */
|
|
386
391
|
const data = {
|
|
387
392
|
component: dirName,
|
|
@@ -40,7 +40,7 @@ export const docs = {
|
|
|
40
40
|
blocks: [
|
|
41
41
|
{
|
|
42
42
|
type: 'prose',
|
|
43
|
-
text: '`Calendar
|
|
43
|
+
text: '`Calendar`, DateInput, DateRangeInput, and DateTimeInput show the Gregorian calendar unless the application chooses another one. Values never change with the calendar: they stay Gregorian ISO dates. {@link generic:i18n-calendars} has the short version.',
|
|
44
44
|
},
|
|
45
45
|
],
|
|
46
46
|
};
|
|
@@ -383,6 +383,15 @@ export function providerLedgerOf(project) {
|
|
|
383
383
|
return PROVIDER_LEDGERS.get(project) ?? new Map();
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
+
/**
|
|
387
|
+
* True when an integration's templates root exists, the only place its
|
|
388
|
+
* templates come from (discoverIntegrationTemplatesForOne).
|
|
389
|
+
* @param {any} integration
|
|
390
|
+
* @returns {boolean}
|
|
391
|
+
*/
|
|
392
|
+
const hasTemplatesRoot = integration =>
|
|
393
|
+
integration?.templates != null && fs.existsSync(integration.templates);
|
|
394
|
+
|
|
386
395
|
/**
|
|
387
396
|
* The single API for reading resolved project configuration. Construct via the
|
|
388
397
|
* async {@link Project.load} factory.
|
|
@@ -1259,15 +1268,24 @@ export class Project {
|
|
|
1259
1268
|
* @returns {Promise<ProjectIntegrationIssue[]>}
|
|
1260
1269
|
*/
|
|
1261
1270
|
async issues() {
|
|
1262
|
-
//
|
|
1263
|
-
//
|
|
1264
|
-
//
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
+
// Each issue these passes find belongs to an integration, because Core's
|
|
1272
|
+
// templates and components declare no replacement. A project with no
|
|
1273
|
+
// integration skips them.
|
|
1274
|
+
if (this.#loadedIntegrations.length > 0) {
|
|
1275
|
+
// Template replacement validity depends on the combined Core +
|
|
1276
|
+
// integration catalog. Resolve it first so issue results never depend
|
|
1277
|
+
// on which discovery method the caller happened to invoke earlier. Only
|
|
1278
|
+
// an integration's own templates can replace one, so with none, Core's
|
|
1279
|
+
// templates stay unread.
|
|
1280
|
+
if (this.#loadedIntegrations.some(hasTemplatesRoot)) {
|
|
1281
|
+
await this.templates();
|
|
1282
|
+
}
|
|
1283
|
+
// Component replacement validity likewise depends on Core plus every
|
|
1284
|
+
// integration's components.
|
|
1285
|
+
await this.componentReplacements();
|
|
1286
|
+
for (const integration of this.#loadedIntegrations) {
|
|
1287
|
+
await this.#collectIssues(integration);
|
|
1288
|
+
}
|
|
1271
1289
|
}
|
|
1272
1290
|
// Return a stable copy so callers can't mutate internal state.
|
|
1273
1291
|
return this.#issues.map(i => ({...i}));
|
|
@@ -7,6 +7,18 @@
|
|
|
7
7
|
* @returns {string | null}
|
|
8
8
|
*/
|
|
9
9
|
export function astryxCliRootOf(file: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* The executable files on the search path named one of `names`, in the order
|
|
12
|
+
* a shell tries them. In each folder, it takes the first name that is a file
|
|
13
|
+
* this user may run. Nothing is started.
|
|
14
|
+
* @param {readonly string[]} names
|
|
15
|
+
* @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
|
|
16
|
+
* @returns {string[]}
|
|
17
|
+
*/
|
|
18
|
+
export function executablesOnSearchPath(names: readonly string[], { searchPath, platform, }?: {
|
|
19
|
+
searchPath?: string;
|
|
20
|
+
platform?: NodeJS.Platform;
|
|
21
|
+
}): string[];
|
|
10
22
|
/**
|
|
11
23
|
* Every `astryx` command on the search path, in the order a shell tries
|
|
12
24
|
* them. The first row is the one that runs.
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* package folder is read from the shim's text.
|
|
14
14
|
*
|
|
15
15
|
* @input the search path and, on Windows, its executable names
|
|
16
|
-
* @output one row per `astryx` command found
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* @output one row per `astryx` command found, and the executable files that
|
|
17
|
+
* any command name finds there
|
|
18
|
+
* @position packages/cli/foundation/env — read by doctor, init --user, the
|
|
19
|
+
* update notices, and swizzle's `gh` lookup.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
import * as fs from 'node:fs';
|
|
@@ -146,6 +147,53 @@ function namesCliPackage(file) {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Whether `file` is a file this user may run. On Windows, any file counts.
|
|
152
|
+
* @param {string} file
|
|
153
|
+
* @param {boolean} windows
|
|
154
|
+
* @returns {boolean}
|
|
155
|
+
*/
|
|
156
|
+
function isRunnableFile(file, windows) {
|
|
157
|
+
try {
|
|
158
|
+
if (!fs.statSync(file).isFile()) return false;
|
|
159
|
+
if (!windows) fs.accessSync(file, fs.constants.X_OK);
|
|
160
|
+
return true;
|
|
161
|
+
} catch {
|
|
162
|
+
// The shell skips a candidate the system cannot read: a missing folder, a
|
|
163
|
+
// stale mount, a symlink loop. `which` and execvp read PATH the same way.
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The executable files on the search path named one of `names`, in the order
|
|
170
|
+
* a shell tries them. In each folder, it takes the first name that is a file
|
|
171
|
+
* this user may run. Nothing is started.
|
|
172
|
+
* @param {readonly string[]} names
|
|
173
|
+
* @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
|
|
174
|
+
* @returns {string[]}
|
|
175
|
+
*/
|
|
176
|
+
export function executablesOnSearchPath(
|
|
177
|
+
names,
|
|
178
|
+
{
|
|
179
|
+
searchPath = process.env.PATH ?? process.env.Path ?? '',
|
|
180
|
+
platform = process.platform,
|
|
181
|
+
} = {},
|
|
182
|
+
) {
|
|
183
|
+
const windows = platform === 'win32';
|
|
184
|
+
/** @type {string[]} */
|
|
185
|
+
const files = [];
|
|
186
|
+
for (const dir of searchPath.split(windows ? ';' : path.delimiter)) {
|
|
187
|
+
if (!dir) continue;
|
|
188
|
+
// One command per folder: the shell runs the first name it finds.
|
|
189
|
+
const file = names
|
|
190
|
+
.map(name => path.join(dir, name))
|
|
191
|
+
.find(candidate => isRunnableFile(candidate, windows));
|
|
192
|
+
if (file !== undefined) files.push(file);
|
|
193
|
+
}
|
|
194
|
+
return files;
|
|
195
|
+
}
|
|
196
|
+
|
|
149
197
|
/**
|
|
150
198
|
* Every `astryx` command on the search path, in the order a shell tries
|
|
151
199
|
* them. The first row is the one that runs.
|
|
@@ -156,50 +204,30 @@ export function astryxCommandsOnSearchPath({
|
|
|
156
204
|
searchPath = process.env.PATH ?? process.env.Path ?? '',
|
|
157
205
|
platform = process.platform,
|
|
158
206
|
} = {}) {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
207
|
+
const names =
|
|
208
|
+
platform === 'win32'
|
|
209
|
+
? ['astryx.cmd', 'astryx.exe', 'astryx.ps1', 'astryx']
|
|
210
|
+
: [COMMAND];
|
|
163
211
|
/** @type {SearchPathCommand[]} */
|
|
164
212
|
const rows = [];
|
|
165
213
|
const seen = new Set();
|
|
166
|
-
for (const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
stat = fs.statSync(file);
|
|
173
|
-
} catch {
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (!stat.isFile()) continue;
|
|
177
|
-
if (!windows) {
|
|
178
|
-
try {
|
|
179
|
-
fs.accessSync(file, fs.constants.X_OK);
|
|
180
|
-
} catch {
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
let key = file;
|
|
185
|
-
try {
|
|
186
|
-
key = fs.realpathSync(file);
|
|
187
|
-
} catch {
|
|
188
|
-
// Keep the path as found.
|
|
189
|
-
}
|
|
190
|
-
if (seen.has(key)) break;
|
|
191
|
-
seen.add(key);
|
|
192
|
-
const cliRoot = astryxCliRootOf(file);
|
|
193
|
-
rows.push({
|
|
194
|
-
file,
|
|
195
|
-
astryx: cliRoot !== null || namesCliPackage(file),
|
|
196
|
-
cliRoot,
|
|
197
|
-
version: cliRoot ? cliVersionAt(cliRoot) : null,
|
|
198
|
-
handsOff: cliRoot ? handsOffAt(cliRoot) : null,
|
|
199
|
-
});
|
|
200
|
-
// One command per folder: the shell runs the first name it finds.
|
|
201
|
-
break;
|
|
214
|
+
for (const file of executablesOnSearchPath(names, {searchPath, platform})) {
|
|
215
|
+
let key = file;
|
|
216
|
+
try {
|
|
217
|
+
key = fs.realpathSync(file);
|
|
218
|
+
} catch {
|
|
219
|
+
// Keep the path as found.
|
|
202
220
|
}
|
|
221
|
+
if (seen.has(key)) continue;
|
|
222
|
+
seen.add(key);
|
|
223
|
+
const cliRoot = astryxCliRootOf(file);
|
|
224
|
+
rows.push({
|
|
225
|
+
file,
|
|
226
|
+
astryx: cliRoot !== null || namesCliPackage(file),
|
|
227
|
+
cliRoot,
|
|
228
|
+
version: cliRoot ? cliVersionAt(cliRoot) : null,
|
|
229
|
+
handsOff: cliRoot ? handsOffAt(cliRoot) : null,
|
|
230
|
+
});
|
|
203
231
|
}
|
|
204
232
|
return rows;
|
|
205
233
|
}
|
|
@@ -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.
|
|
3
|
+
"version": "0.7.9-canary.6fc2bff",
|
|
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.
|
|
128
|
-
"@astryxdesign/core": "0.7.9-canary.
|
|
129
|
-
"@astryxdesign/lab": "0.7.9-canary.
|
|
130
|
-
"@astryxdesign/theme-neutral": "0.7.9-canary.
|
|
127
|
+
"@astryxdesign/charts": "0.7.9-canary.6fc2bff",
|
|
128
|
+
"@astryxdesign/core": "0.7.9-canary.6fc2bff",
|
|
129
|
+
"@astryxdesign/lab": "0.7.9-canary.6fc2bff",
|
|
130
|
+
"@astryxdesign/theme-neutral": "0.7.9-canary.6fc2bff"
|
|
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.
|
|
148
|
-
"@astryxdesign/core": "0.7.9-canary.
|
|
149
|
-
"@astryxdesign/lab": "0.7.9-canary.
|
|
150
|
-
"@astryxdesign/theme-neutral": "0.7.9-canary.
|
|
147
|
+
"@astryxdesign/charts": "0.7.9-canary.6fc2bff",
|
|
148
|
+
"@astryxdesign/core": "0.7.9-canary.6fc2bff",
|
|
149
|
+
"@astryxdesign/lab": "0.7.9-canary.6fc2bff",
|
|
150
|
+
"@astryxdesign/theme-neutral": "0.7.9-canary.6fc2bff",
|
|
151
151
|
"@heroicons/react": "^2.2.0",
|
|
152
152
|
"@stylexjs/stylex": "^0.19.0",
|
|
153
153
|
"@types/babel__core": "^7.20.5",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
-
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Check if `gh` CLI is installed and authenticated.
|
|
6
|
-
* Returns true if ready, false otherwise.
|
|
7
|
-
*/
|
|
8
|
-
export function checkGhCli(): boolean;
|
package/api/swizzle/_github.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file GitHub utilities for Astryx CLI
|
|
5
|
-
*
|
|
6
|
-
* Shared helpers for interacting with the GitHub CLI (`gh`).
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {execFileSync} from 'node:child_process';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Check if `gh` CLI is installed and authenticated.
|
|
13
|
-
* Returns true if ready, false otherwise.
|
|
14
|
-
*/
|
|
15
|
-
export function checkGhCli() {
|
|
16
|
-
try {
|
|
17
|
-
execFileSync('gh', ['auth', 'status'], {stdio: 'ignore'});
|
|
18
|
-
return true;
|
|
19
|
-
} catch {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|