mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
* fix(setup): refresh registrations from a removed npx cache entry npx rea-agents setup saves REA's script in npm's _npx cache. After npm prunes that entry, setup could not read the package manifest, marked the registration unknown and asked for a manual config edit. A saved script with setup's exact npx layout that no longer exists is now REA-owned and stale, so npx rea-agents@latest setup replaces it and doctor names that command. The npx cache matcher moves to one module shared by doctor and setup. * docs(agents): keep npx rea-agents setup as the onboarding path * test(setup): run real npx setup through a cache prune and repair The end-to-end run showed POSIX setup saves npm exec's node_modules/.bin/rea alias, not the package script, so removed-npx recognition now accepts both layouts setup writes.
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
/**
|
|
* Lexical facts about package-runner cache paths, shared by doctor's PATH
|
|
* listing and setup's ownership of saved launchers so both read one layout.
|
|
*/
|
|
|
|
/** libnpmexec keeps the first 16 hex digits of the sha512 spec hash. */
|
|
const NPX_CACHE_KEY_HEX_DIGITS = 16;
|
|
const HEX_DIGITS = /^[a-f0-9]+$/u;
|
|
|
|
export const hexDigits = (
|
|
segment: string | undefined,
|
|
width: number,
|
|
): boolean =>
|
|
segment !== undefined && segment.length === width && HEX_DIGITS.test(segment);
|
|
|
|
export const segmentAt = (
|
|
segments: readonly string[],
|
|
index: number,
|
|
): string | undefined => (index >= 0 ? segments[index] : undefined);
|
|
|
|
/**
|
|
* Split a path as written, before symlink resolution, because the cache marker
|
|
* is on that spelling. Windows folds case and treats `\` as a separator. POSIX
|
|
* keeps the spelling: a backslash can belong to a name.
|
|
*/
|
|
export const packageRunnerSegments = (
|
|
path: string,
|
|
platform: NodeJS.Platform,
|
|
): readonly string[] =>
|
|
(platform === "win32" ? path.replace(/\\/gu, "/").toLowerCase() : path)
|
|
.split("/")
|
|
.filter((segment) => segment.length > 0);
|
|
|
|
/** Whether the `node_modules` segment at `modules` sits in `_npx/<16 hex>`. */
|
|
export const npxCache = (
|
|
segments: readonly string[],
|
|
modules: number,
|
|
): boolean =>
|
|
segmentAt(segments, modules - 2) === "_npx" &&
|
|
hexDigits(segmentAt(segments, modules - 1), NPX_CACHE_KEY_HEX_DIGITS);
|