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
36 lines (35 loc) • 1.42 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/.
/**
* Shared materialization skeleton for mirror caches (git repos, website
* snapshots). A marker file records that the mirror was materialized on this
* host and its mtime records the last successful refresh. A usable
* materialized mirror is served as-is: age never triggers a refresh. Only a
* missing marker, an unusable mirror, or `force` (`akm bundle update`) does.
* A failed refresh is reported, never masked: the refresh implementations
* leave the previous copy on disk, so search keeps serving it, but the caller
* sees the error.
*/
import fs from "node:fs";
/**
* Run the materialized → refresh ladder around `refresh()`. Resolves when the
* cached copy is usable as-is or has just been refreshed; a failed refresh
* rethrows its error.
*/
export async function withFreshnessCache(options) {
const usable = options.isUsable ?? (() => true);
let materialized = false;
try {
// asset-io: install refresh marker
fs.statSync(options.markerPath);
materialized = true;
}
catch {
/* no marker — never successfully refreshed */
}
if (!options.force && materialized && usable()) {
return;
}
await options.refresh();
}