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
59 lines (58 loc) • 2.51 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/.
// ── Test seam ────────────────────────────────────────────────────────────────
// Swap-and-restore override. Inert in production; only tests call the setter
// (via tests/_helpers/seams.ts `overrideSeam`, never directly).
let clackFake;
/** TEST-ONLY. Swap the clack prompt surface; pass undefined to restore. */
export function _setClackForTests(fake) {
clackFake = fake;
}
// @clack/prompts reads process.stdout and process.stderr when it is loaded, which on Bun makes an inherited
// pipe non-blocking. A command that prompts loads it first with loadPrompts(); a command that never prompts
// never loads it. A dynamic import is the one form every bundler keeps out of startup.
let realClack;
/** Load the prompt library. Every command that prompts, or shows a spinner, awaits this first. */
export async function loadPrompts() {
realClack ??= (await import("@clack/prompts"));
}
/** The loaded library; a prompt used before `loadPrompts()` is a programming error, reported as one. */
function real() {
if (!realClack)
throw new Error("A prompt was used before loadPrompts().");
return realClack;
}
/** Delegator with the real export's exact type; reads the fake at call time. */
function bind(name) {
return ((...args) => {
const impl = (clackFake?.[name] ?? real()[name]);
return impl(...args);
});
}
function bindLog(name) {
return ((...args) => {
const impl = (clackFake?.log?.[name] ?? real().log[name]);
return impl(...args);
});
}
export const intro = bind("intro");
export const outro = bind("outro");
export const cancel = bind("cancel");
export const confirm = bind("confirm");
export const select = bind("select");
export const multiselect = bind("multiselect");
export const text = bind("text");
export const password = bind("password");
export const spinner = bind("spinner");
export const note = bind("note");
export const isCancel = bind("isCancel");
export const log = {
message: bindLog("message"),
info: bindLog("info"),
success: bindLog("success"),
step: bindLog("step"),
warn: bindLog("warn"),
warning: bindLog("warning"),
error: bindLog("error"),
};