akm-cli
Version:
akm (Agent Knowledge Manager) — a portable, local-first capability library for AI agents. Discover, load, share, and improve reusable skills, scripts, workflows, and knowledge across any shell-capable coding agent, including Claude Code, OpenCode, and Cur
40 lines (39 loc) • 1.48 kB
JavaScript
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
/**
* Materialize an install ref through the matching source implementation.
*/
import { UsageError } from "../../core/errors.js";
import { parseRegistryRef } from "../../registry/resolve.js";
import { detectStashRoot } from "./provider-utils.js";
export async function syncFromRef(ref, options) {
const parsed = parseRegistryRef(ref);
if (parsed.source === "local") {
return syncLocalRef(parsed, options);
}
if (parsed.source === "npm") {
const { syncNpmRef } = await import("./npm.js");
return syncNpmRef(ref, options);
}
if (parsed.source === "git" || parsed.source === "github") {
const { syncGitRef } = await import("./git-install.js");
return syncGitRef(ref, options);
}
throw new UsageError(`No syncable provider for ref: ${ref}`);
}
function syncLocalRef(parsed, options) {
const stashRoot = detectStashRoot(parsed.sourcePath);
const syncedAt = (options?.now ?? new Date()).toISOString();
return {
id: parsed.id,
source: "local",
ref: parsed.ref,
artifactUrl: parsed.sourcePath,
contentDir: stashRoot,
cacheDir: parsed.sourcePath,
extractedDir: parsed.sourcePath,
writable: options?.writable,
syncedAt,
};
}