@skild/core 0.5.0 → 0.5.2

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/dist/index.d.ts CHANGED
@@ -159,6 +159,7 @@ declare function materializeSourceToTemp(source: string): Promise<{
159
159
  }>;
160
160
 
161
161
  declare function toDegitPath(url: string): string;
162
+ declare function stripSourceRef(source: string): string;
162
163
  /**
163
164
  * Derive a child source spec from a base source and a relative path.
164
165
  *
@@ -244,4 +245,4 @@ declare function uninstallSkill(name: string, options?: InstallOptions & {
244
245
  }): void;
245
246
  declare function updateSkill(name?: string, options?: UpdateOptions): Promise<InstallRecord[]>;
246
247
 
247
- export { DEFAULT_REGISTRY_URL, type DependencySourceType, type GlobalConfig, type InstallOptions, type InstallRecord, type InstallScope, type InstalledDependency, type ListOptions, type Lockfile, PLATFORMS, type Platform, type RegistryAuth, SkildError, type SkillFrontmatter, type SkillValidationIssue, type SkillValidationResult, type UpdateOptions, assertValidAlias, canonicalNameToInstallDirName, clearRegistryAuth, deriveChildSource, downloadAndExtractTarball, fetchWithTimeout, getSkillInfo, getSkillInstallDir, getSkillsDir, initSkill, installRegistrySkill, installSkill, isValidAlias, listAllSkills, listSkills, loadOrCreateGlobalConfig, loadRegistryAuth, materializeSourceToDir, materializeSourceToTemp, normalizeAlias, parseRegistrySpecifier, resolveRegistryAlias, resolveRegistryUrl, resolveRegistryVersion, saveRegistryAuth, searchRegistrySkills, splitCanonicalName, toDegitPath, uninstallSkill, updateSkill, validateSkill, validateSkillDir };
248
+ export { DEFAULT_REGISTRY_URL, type DependencySourceType, type GlobalConfig, type InstallOptions, type InstallRecord, type InstallScope, type InstalledDependency, type ListOptions, type Lockfile, PLATFORMS, type Platform, type RegistryAuth, SkildError, type SkillFrontmatter, type SkillValidationIssue, type SkillValidationResult, type UpdateOptions, assertValidAlias, canonicalNameToInstallDirName, clearRegistryAuth, deriveChildSource, downloadAndExtractTarball, fetchWithTimeout, getSkillInfo, getSkillInstallDir, getSkillsDir, initSkill, installRegistrySkill, installSkill, isValidAlias, listAllSkills, listSkills, loadOrCreateGlobalConfig, loadRegistryAuth, materializeSourceToDir, materializeSourceToTemp, normalizeAlias, parseRegistrySpecifier, resolveRegistryAlias, resolveRegistryUrl, resolveRegistryVersion, saveRegistryAuth, searchRegistrySkills, splitCanonicalName, stripSourceRef, toDegitPath, uninstallSkill, updateSkill, validateSkill, validateSkillDir };
package/dist/index.js CHANGED
@@ -433,6 +433,11 @@ function toDegitPath(url) {
433
433
  if (repoMatch) return repoMatch[1].replace(/\.git$/, "");
434
434
  return url;
435
435
  }
436
+ function stripSourceRef(source) {
437
+ const hashIndex = source.indexOf("#");
438
+ if (hashIndex === -1) return source;
439
+ return source.slice(0, hashIndex);
440
+ }
436
441
  function normalizeRelPath(relPath) {
437
442
  return relPath.split(path6.sep).join("/").replace(/^\/+/, "").replace(/\/+$/, "");
438
443
  }
@@ -455,6 +460,24 @@ async function cloneRemote(degitSrc, targetPath) {
455
460
  const emitter = degit(degitSrc, { force: true, verbose: false });
456
461
  await emitter.clone(targetPath);
457
462
  }
463
+ function isMissingRefError(error) {
464
+ if (!error) return false;
465
+ const message = error instanceof Error ? error.message : String(error);
466
+ return /could not find commit hash/i.test(message);
467
+ }
468
+ async function cloneRemoteWithFallback(degitSrc, targetPath) {
469
+ try {
470
+ await cloneRemote(degitSrc, targetPath);
471
+ return degitSrc;
472
+ } catch (error) {
473
+ if (!degitSrc.includes("#") || !isMissingRefError(error)) {
474
+ throw error;
475
+ }
476
+ }
477
+ const fallbackSrc = stripSourceRef(degitSrc);
478
+ await cloneRemote(fallbackSrc, targetPath);
479
+ return fallbackSrc;
480
+ }
458
481
  async function materializeSourceToDir(input) {
459
482
  const sourceType = classifySource(input.source);
460
483
  const targetDir = path7.resolve(input.targetDir);
@@ -472,8 +495,8 @@ async function materializeSourceToDir(input) {
472
495
  return { sourceType: "local", materializedFrom: localPath };
473
496
  }
474
497
  const degitPath = toDegitPath(input.source);
475
- await cloneRemote(degitPath, targetDir);
476
- return { sourceType, materializedFrom: degitPath };
498
+ const materializedFrom = await cloneRemoteWithFallback(degitPath, targetDir);
499
+ return { sourceType, materializedFrom };
477
500
  }
478
501
  async function materializeSourceToTemp(source) {
479
502
  const sourceType = classifySource(source);
@@ -611,13 +634,22 @@ async function resolveRegistryAlias(registryUrl, alias) {
611
634
  throw new SkildError("REGISTRY_RESOLVE_FAILED", `Failed to resolve alias "${a}" (${res.status}). ${text}`.trim());
612
635
  }
613
636
  const json = await res.json();
614
- if (!json?.ok || !json.type || typeof json.spec !== "string" || !json.spec.trim()) {
637
+ const normalizedSpec = normalizeResolvedSpec(json?.spec);
638
+ if (!json?.ok || !json.type || !normalizedSpec) {
615
639
  throw new SkildError("REGISTRY_RESOLVE_FAILED", `Invalid registry response for alias "${a}".`);
616
640
  }
617
- if (json.type === "registry") return { type: "registry", spec: json.spec.trim() };
618
- if (json.type === "linked") return { type: "linked", spec: json.spec.trim() };
641
+ if (json.type === "registry") return { type: "registry", spec: normalizedSpec };
642
+ if (json.type === "linked") return { type: "linked", spec: normalizedSpec };
619
643
  throw new SkildError("REGISTRY_RESOLVE_FAILED", `Unsupported alias target type "${json.type}".`);
620
644
  }
645
+ function normalizeResolvedSpec(spec) {
646
+ if (typeof spec !== "string") return "";
647
+ let normalized = spec.trim();
648
+ while (normalized.length >= 2 && (normalized.startsWith('"') && normalized.endsWith('"') || normalized.startsWith("'") && normalized.endsWith("'"))) {
649
+ normalized = normalized.slice(1, -1).trim();
650
+ }
651
+ return normalized;
652
+ }
621
653
  async function downloadAndExtractTarball(resolved, tempRoot, stagingDir) {
622
654
  const res = await fetchWithTimeout(resolved.tarballUrl, {}, 3e4);
623
655
  if (!res.ok) {
@@ -1202,6 +1234,7 @@ export {
1202
1234
  saveRegistryAuth,
1203
1235
  searchRegistrySkills,
1204
1236
  splitCanonicalName,
1237
+ stripSourceRef,
1205
1238
  toDegitPath,
1206
1239
  uninstallSkill,
1207
1240
  updateSkill,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skild/core",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Skild core library (headless) for installing, validating, and managing Agent Skills locally.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",