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
25 lines (24 loc) • 1.15 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/.
import { spawnSync } from "node:child_process";
import { redactUrlCredentials } from "./redaction.js";
/**
* Shared subprocess wrapper for `git` invocations. Disables git's interactive
* terminal prompt so a missing credential never hangs the process.
*/
export function runGit(args, options) {
return spawnSync("git", args, {
encoding: "utf8",
...options,
env: { ...process.env, ...options?.env, GIT_TERMINAL_PROMPT: "0" },
});
}
/**
* A remote (or URL) as an origin check compares it: as git expands it, so a `url.<base>.insteadOf` rule that
* rewrites a URL names the same origin, without its credentials, trailing `/` or `.git`. Undefined when git cannot.
*/
export function comparableRemoteUrl(repoDir, remote) {
const url = runGit(["-C", repoDir, "ls-remote", "--get-url", remote]);
return url.status === 0 ? redactUrlCredentials(url.stdout.trim()).replace(/(\.git)?\/*$/i, "") : undefined;
}