Skip to content

Commit 7e1587f

Browse files
Vitozhu04claude
andauthored
fix(cli): pass the CLI version into the skills check instead of importing it
scripts/clawhub-unlist-retired.mjs loads skillsManifest.ts from source under plain node, which cannot resolve a relative `../version.js` import. Callers now pass `cliVersion` (and skillsSourceRef takes it as an argument), so the module keeps importing only node builtins. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8f94b1a commit 7e1587f

5 files changed

Lines changed: 27 additions & 24 deletions

File tree

‎packages/cli/src/commands/skills.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as clack from "../ui/prompts.js";
55
import { c } from "../ui/colors.js";
66
import { diag } from "../ui/diagnostics.js";
77
import { buildNpxCommand } from "../utils/npxCommand.js";
8+
import { VERSION } from "../version.js";
89
import { withMeta } from "../utils/updateCheck.js";
910
import {
1011
checkSkills,
@@ -253,7 +254,7 @@ async function installSkills(
253254

254255
if (!skillsToolingReady(opts.strict ?? false)) return;
255256

256-
const ref = await skillsSourceRef();
257+
const ref = await skillsSourceRef(VERSION);
257258
// stderr (via diag): installSkills runs on the `skills update --json` path before
258259
// its JSON envelope is written to stdout — progress here must not corrupt it.
259260
for (const source of SOURCES) {
@@ -346,7 +347,7 @@ export async function updateSkills(
346347
// that no longer exists, and verifyInstalled would strict-throw on a
347348
// "failure" that was never real. Resolving canonically means a retired
348349
// skill simply never appears as a target in the first place.
349-
check = await checkSkills({ cwd: opts.cwd, canonical: true });
350+
check = await checkSkills({ cwd: opts.cwd, canonical: true, cliVersion: VERSION });
350351
} catch (err) {
351352
// A *malformed* canonical manifest (the server was reached, but served a
352353
// bad shape) is otherwise indistinguishable from being offline — both fall
@@ -577,6 +578,7 @@ const checkCommand = defineCommand({
577578
const result = await checkSkills({
578579
dir: args.dir,
579580
source: args.source,
581+
cliVersion: VERSION,
580582
});
581583

582584
if (args.json) console.log(JSON.stringify(withMeta(result), null, 2));

‎packages/cli/src/utils/skillsManifest.releaseTag.test.ts‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// A release build of the CLI reads its skills at its own release tag. The
2-
// version is a build-time constant, so this file mocks it to a released one
3-
// (the sibling skillsManifest.test.ts runs as the dev build, "0.0.0-dev").
1+
// A release build of the CLI reads its skills at its own release tag.
42

53
import { execFile } from "node:child_process";
64
import { mkdtempSync, rmSync } from "node:fs";
@@ -9,8 +7,6 @@ import { join } from "node:path";
97
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
108
import { checkSkills, cliReleaseTag, MANIFEST_FILE, skillsSourceRef } from "./skillsManifest.js";
119

12-
vi.mock("../version.js", () => ({ VERSION: "0.9.3" }));
13-
1410
const lsRemote = vi.hoisted(() => ({
1511
tags: new Set<string>(),
1612
tagSha: "b".repeat(40),
@@ -73,31 +69,31 @@ describe("cliReleaseTag", () => {
7369
describe("skillsSourceRef", () => {
7470
it("is the CLI's release tag when the repo has it", async () => {
7571
lsRemote.tags.add("refs/tags/v0.9.3");
76-
expect(await skillsSourceRef()).toBe("v0.9.3");
72+
expect(await skillsSourceRef("0.9.3")).toBe("v0.9.3");
7773
});
7874

7975
it("falls back to main for a version the repo has no tag for", async () => {
80-
expect(await skillsSourceRef()).toBe("main");
76+
expect(await skillsSourceRef("0.9.3")).toBe("main");
8177
});
8278

8379
it("is main for a dev build without asking git", async () => {
84-
expect(await skillsSourceRef("heygen-com/hyperframes", "0.0.0-dev")).toBe("main");
80+
expect(await skillsSourceRef("0.0.0-dev")).toBe("main");
8581
expect(vi.mocked(execFile)).not.toHaveBeenCalled();
8682
});
8783
});
8884

8985
describe("checkSkills on a release build", () => {
9086
it("compares against the manifest at the CLI's release tag, not main", async () => {
9187
lsRemote.tags.add("refs/tags/v0.9.3");
92-
await checkSkills({ cwd: root, home: root, canonical: true });
88+
await checkSkills({ cwd: root, home: root, canonical: true, cliVersion: "0.9.3" });
9389
expect(vi.mocked(fetch)).toHaveBeenCalledWith(
9490
`https://raw.githubusercontent.com/heygen-com/hyperframes/v0.9.3/${MANIFEST_FILE}`,
9591
expect.anything(),
9692
);
9793
});
9894

9995
it("compares against main when the tag does not exist", async () => {
100-
await checkSkills({ cwd: root, home: root, canonical: true });
96+
await checkSkills({ cwd: root, home: root, canonical: true, cliVersion: "0.9.3" });
10197
expect(vi.mocked(fetch)).toHaveBeenCalledWith(
10298
`https://raw.githubusercontent.com/heygen-com/hyperframes/${lsRemote.mainSha}/${MANIFEST_FILE}`,
10399
expect.anything(),

‎packages/cli/src/utils/skillsManifest.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2121
import { homedir } from "node:os";
2222
import { isAbsolute, join, relative, resolve, sep } from "node:path";
2323
import { promisify } from "node:util";
24-
import { VERSION } from "../version.js";
2524

2625
const execFileAsync = promisify(execFile);
2726

@@ -624,16 +623,16 @@ async function remoteRefSha(repoSlug: string, ref: string): Promise<string | nul
624623
}
625624

626625
/** The release tag (`v<version>`) of a published CLI build; null for a dev or pre-release build. */
627-
export function cliReleaseTag(version: string = VERSION): string | null {
626+
export function cliReleaseTag(version: string): string | null {
628627
return /^\d+\.\d+\.\d+$/.test(version) ? `v${version}` : null;
629628
}
630629

631630
/** Where skills install from and are checked against: this CLI's release tag, else `main`. */
632631
export async function skillsSourceRef(
632+
cliVersion: string,
633633
repoSlug: string = DEFAULT_REPO_SLUG,
634-
version: string = VERSION,
635634
): Promise<string> {
636-
const tag = cliReleaseTag(version);
635+
const tag = cliReleaseTag(cliVersion);
637636
if (!tag) return "main";
638637
return (await remoteRefSha(repoSlug, `refs/tags/${tag}`)) ? tag : "main";
639638
}
@@ -654,11 +653,11 @@ function resolveLocalManifest(source: string): SkillsManifest {
654653
* moves), `main` SHA-pinned via `git ls-remote` to dodge raw-CDN lag, falling
655654
* back to the branch URL when git is unavailable.
656655
*/
657-
async function fetchRemoteManifest(source?: string): Promise<SkillsManifest> {
656+
async function fetchRemoteManifest(source?: string, cliVersion?: string): Promise<SkillsManifest> {
658657
if (source?.startsWith("http")) return fetchManifest(source);
659658

660659
const repoSlug = source ?? DEFAULT_REPO_SLUG;
661-
const ref = await skillsSourceRef(repoSlug);
660+
const ref = cliVersion ? await skillsSourceRef(cliVersion, repoSlug) : "main";
662661
if (ref !== "main") {
663662
return fetchManifest(`https://raw.githubusercontent.com/${repoSlug}/${ref}/${MANIFEST_FILE}`);
664663
}
@@ -693,7 +692,7 @@ async function fetchRemoteManifest(source?: string): Promise<SkillsManifest> {
693692
async function resolveLatestManifest(
694693
source?: string,
695694
cwd = process.cwd(),
696-
opts: { canonical?: boolean } = {},
695+
opts: { canonical?: boolean; cliVersion?: string } = {},
697696
): Promise<SkillsManifest> {
698697
// A local path is a relative one (./ ../) or an absolute one — isAbsolute
699698
// covers POSIX `/…` and Windows `C:\…` / `\…` on their respective platforms.
@@ -704,7 +703,7 @@ async function resolveLatestManifest(
704703
const repoManifest = findRepoManifest(cwd);
705704
if (repoManifest) return JSON.parse(readFileSync(repoManifest, "utf8")) as SkillsManifest;
706705
}
707-
return fetchRemoteManifest(source);
706+
return fetchRemoteManifest(source, opts.cliVersion);
708707
}
709708

710709
/**
@@ -719,9 +718,14 @@ export async function checkSkills(
719718
home?: string;
720719
/** See resolveLatestManifest — bypass the in-repo manifest shortcut. */
721720
canonical?: boolean;
721+
/** Read the remote manifest at this CLI version's release tag (see skillsSourceRef). */
722+
cliVersion?: string;
722723
} = {},
723724
): Promise<SkillsCheckResult> {
724-
const latest = await resolveLatestManifest(opts.source, opts.cwd, { canonical: opts.canonical });
725+
const latest = await resolveLatestManifest(opts.source, opts.cwd, {
726+
canonical: opts.canonical,
727+
cliVersion: opts.cliVersion,
728+
});
725729
const skillNames = Object.keys(latest.skills);
726730
const root = locateInstall(skillNames, { dir: opts.dir, cwd: opts.cwd, home: opts.home });
727731
// A directory sharing a name with one of ours can belong to another publisher.

‎packages/cli/src/utils/skillsUpdateCheck.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe("skillsUpdateCheck", () => {
114114
// Must resolve against the canonical upstream manifest, not a possibly
115115
// stale in-repo skills-manifest.json, so this nudge agrees with what
116116
// `updateSkills` would actually reconcile.
117-
expect(mockCheckSkills).toHaveBeenCalledWith({ canonical: true });
117+
expect(mockCheckSkills).toHaveBeenCalledWith({ canonical: true, cliVersion: "0.0.0-dev" });
118118
});
119119

120120
it("does not persist anything when no install was located (nothing meaningful to cache)", async () => {
@@ -228,7 +228,7 @@ describe("skillsUpdateCheck", () => {
228228

229229
expect(skillsCheckDue()).toBe(true);
230230
await refreshSkillsCache();
231-
expect(mockCheckSkills).toHaveBeenCalledWith({ canonical: true });
231+
expect(mockCheckSkills).toHaveBeenCalledWith({ canonical: true, cliVersion: "0.0.0-dev" });
232232
expect(config).toMatchObject({ skillsUpdateAvailable: false, skillsOutdatedCount: 0 });
233233
});
234234

‎packages/cli/src/utils/skillsUpdateCheck.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { isUnattended } from "./attendedTerminal.js";
1313
import { hostAnswers } from "./hostAnswers.js";
1414
import { checkSkills } from "./skillsManifest.js";
1515
import { updateCheckDisabled } from "./updateCheck.js";
16+
import { VERSION } from "../version.js";
1617

1718
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24 hours
1819

@@ -43,7 +44,7 @@ export async function refreshSkillsCache(): Promise<void> {
4344
// `canonical: true` so this nudge's counts agree with `updateSkills`'s
4445
// source of truth — otherwise a stale in-repo skills-manifest.json (e.g.
4546
// inside a hyperframes checkout) can produce a false-positive count here.
46-
const result = await checkSkills({ canonical: true });
47+
const result = await checkSkills({ canonical: true, cliVersion: VERSION });
4748
// Only record a meaningful check when skills were actually found.
4849
if (result.location) {
4950
// Fresh read: this runs in a background child, beside the command's own config writes.

0 commit comments

Comments
 (0)