@@ -19,7 +19,7 @@ import { execFile } from "node:child_process";
1919import { createHash } from "node:crypto" ;
2020import { existsSync , readdirSync , readFileSync , statSync } from "node:fs" ;
2121import { homedir } from "node:os" ;
22- import { isAbsolute , join , relative , sep } from "node:path" ;
22+ import { isAbsolute , join , relative , resolve , sep } from "node:path" ;
2323import { promisify } from "node:util" ;
2424
2525const execFileAsync = promisify ( execFile ) ;
@@ -86,6 +86,13 @@ export interface SkillsCheckResult {
8686 updateAvailable : boolean ;
8787 summary : { current : number ; outdated : number ; missing : number ; removed : number } ;
8888 skills : SkillDiff [ ] ;
89+ /**
90+ * True when an install was located but the upstream skills lock was absent at
91+ * the expected path, so removed-detection couldn't run (it silently reports
92+ * zero removed). Lets the CLI warn instead of misreporting "up to date" — a
93+ * guard against the lock path silently no-op'ing if upstream moves it.
94+ */
95+ lockMissing : boolean ;
8996}
9097
9198const DEFAULT_REPO_SLUG = "heygen-com/hyperframes" ;
@@ -212,18 +219,41 @@ function discoverSkillRoots(base: string, scope: "project" | "global"): SkillRoo
212219 } ) ;
213220}
214221
222+ /**
223+ * Decide whether an explicit `--dir` is a project- or global-scoped install, so
224+ * removed-detection reads the *right* lock. The upstream `skills` CLI keeps two
225+ * locks: a project lock at `<cwd>/skills-lock.json` and a global lock under
226+ * `$HOME` (see lockPathForScope). A `--dir` that lives under `$HOME` (e.g.
227+ * `~/.claude/skills`) is a global install; one under the project tree (or
228+ * anywhere else) is treated as project. Without this, `--dir ~/.claude/skills`
229+ * was always scoped "project", so detectRemoved looked for a non-existent
230+ * `<cwd>/skills-lock.json` and silently found zero removed skills.
231+ */
232+ function scopeForDir ( dir : string , home : string ) : "project" | "global" {
233+ const norm = ( p : string ) : string => {
234+ const r = resolve ( p ) ;
235+ return r . endsWith ( sep ) ? r : r + sep ;
236+ } ;
237+ return norm ( dir ) . startsWith ( norm ( home ) ) ? "global" : "project" ;
238+ }
239+
215240/**
216241 * Find the first skill root that actually contains HyperFrames skills. A
217- * `--dir` override (if given) is treated as a `.../skills` directory directly.
218- * Otherwise scan project (cwd) then global ($HOME), auto-discovering hosts.
242+ * `--dir` override (if given) is treated as a `.../skills` directory directly;
243+ * its scope is inferred (see scopeForDir) so removed-detection reads the right
244+ * lock. Otherwise scan project (cwd) then global ($HOME), auto-discovering hosts.
219245 */
220246function locateInstall (
221247 skillNames : string [ ] ,
222248 opts : { dir ?: string ; cwd ?: string ; home ?: string } = { } ,
223249) : SkillRoot | null {
224250 if ( opts . dir ) {
225251 return existsSync ( opts . dir )
226- ? { dir : opts . dir , agent : agentFromDir ( opts . dir ) , scope : "project" }
252+ ? {
253+ dir : opts . dir ,
254+ agent : agentFromDir ( opts . dir ) ,
255+ scope : scopeForDir ( opts . dir , opts . home ?? homedir ( ) ) ,
256+ }
227257 : null ;
228258 }
229259 const roots = [
@@ -327,7 +357,19 @@ export function skillsAttributedToSource(lock: SkillLock | null, source: string)
327357 . map ( ( [ name ] ) => name ) ;
328358}
329359
330- /** Locate the vercel-labs/skills lock for a scope, mirroring that CLI's paths. */
360+ // Removed-detection reads the vercel-labs/skills lock, whose on-disk paths live
361+ // in *their* repo, not ours — so if upstream moves the lock, our cross-reference
362+ // silently finds nothing and `detectRemoved` no-ops without a peep. Pin the
363+ // upstream version these paths were verified against so a future bump is a
364+ // deliberate, reviewable edit (re-check src/skill-lock.ts `getSkillLockPath`
365+ // and src/local-lock.ts `getLocalLockPath` when bumping):
366+ // - global: $XDG_STATE_HOME/skills/.skill-lock.json else ~/.agents/.skill-lock.json
367+ // - project: <cwd>/skills-lock.json
368+ // https://github.com/vercel-labs/skills/blob/v1.5.13/src/skill-lock.ts (global)
369+ // https://github.com/vercel-labs/skills/blob/v1.5.13/src/local-lock.ts (project)
370+ export const SKILLS_CLI_LOCK_PATHS_VERIFIED_AT = "vercel-labs/[email protected] " ; 371+
372+ /** Locate the vercel-labs/skills lock for a scope (paths pinned to the version above). */
331373function lockPathForScope (
332374 scope : "project" | "global" ,
333375 opts : { cwd ?: string ; home ?: string } ,
@@ -347,17 +389,24 @@ function readSkillLock(path: string): SkillLock | null {
347389 }
348390}
349391
392+ interface RemovedResult {
393+ removed : SkillDiff [ ] ;
394+ /** The lock was absent at the expected path — removed-detection silently no-ops. */
395+ lockMissing : boolean ;
396+ }
397+
350398/** Skills the lock attributes to our source that the manifest no longer ships. */
351399function detectRemoved (
352400 root : SkillRoot ,
353401 latest : SkillsManifest ,
354402 opts : { cwd ?: string ; home ?: string } ,
355- ) : SkillDiff [ ] {
403+ ) : RemovedResult {
356404 const lock = readSkillLock ( lockPathForScope ( root . scope , opts ) ) ;
357- return skillsAttributedToSource ( lock , latest . source )
405+ const removed = skillsAttributedToSource ( lock , latest . source )
358406 . filter ( ( name ) => ! ( name in latest . skills ) )
359407 . sort ( )
360408 . map ( ( name ) => ( { name, status : "removed" as const } ) ) ;
409+ return { removed, lockMissing : lock === null } ;
361410}
362411
363412// ── Resolving the "latest" manifest ──────────────────────────────────────────
@@ -487,7 +536,10 @@ export async function checkSkills(
487536 const root = locateInstall ( skillNames , { dir : opts . dir , cwd : opts . cwd , home : opts . home } ) ;
488537 const installed = root ? hashInstalled ( root , skillNames ) : { } ;
489538 const diff = diffSkills ( installed , latest ) ;
490- const removed = root ? detectRemoved ( root , latest , { cwd : opts . cwd , home : opts . home } ) : [ ] ;
539+ const removedResult = root
540+ ? detectRemoved ( root , latest , { cwd : opts . cwd , home : opts . home } )
541+ : { removed : [ ] , lockMissing : false } ;
542+ const { removed, lockMissing } = removedResult ;
491543 return {
492544 location : root ?. dir ?? null ,
493545 agent : root ?. agent ?? null ,
@@ -497,5 +549,6 @@ export async function checkSkills(
497549 updateAvailable : diff . updateAvailable || removed . length > 0 ,
498550 summary : { ...diff . summary , removed : removed . length } ,
499551 skills : [ ...diff . skills , ...removed ] ,
552+ lockMissing,
500553 } ;
501554}
0 commit comments