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
51 lines (50 loc) • 2.29 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/.
/**
* Where the user's OpenCode keeps its files: the XDG base directories on every
* platform (OpenCode's own `global-roots` does not special-case macOS or
* Windows), each with an `opencode` folder. The one place akm computes them.
*/
import os from "node:os";
import path from "node:path";
import { getDataDir } from "../../../core/paths.js";
function xdgRoot(name, fallback, env) {
const set = env[name]?.trim();
if (set)
return path.join(set, "opencode");
const home = env.HOME?.trim() || env.USERPROFILE?.trim() || os.homedir();
return path.join(home, ...fallback, "opencode");
}
/** `$XDG_DATA_HOME/opencode`: the user's `opencode.db`. */
function opencodeDataDir(env = process.env) {
return xdgRoot("XDG_DATA_HOME", [".local", "share"], env);
}
/** `$XDG_CACHE_HOME/opencode`: the plugin packages it installed. */
export function opencodeCacheDir(env = process.env) {
return xdgRoot("XDG_CACHE_HOME", [".cache"], env);
}
/** `$OPENCODE_CONFIG_DIR`, else `$XDG_CONFIG_HOME/opencode`: `opencode.json`, agents and plugins. */
export function opencodeConfigDir(env = process.env) {
return env.OPENCODE_CONFIG_DIR?.trim() || xdgRoot("XDG_CONFIG_HOME", [".config"], env);
}
/** OpenCode's SQLite session store, in OpenCode's data directory and in akm's. */
export function databaseIn(directory) {
return path.join(directory, "opencode.db");
}
/**
* Everything akm's own OpenCode runtime keeps, under akm's data directory: the
* four XDG roots it is started with (`config`, `data`, `cache`, `state`) and its
* `tmp`. Nothing of the user's OpenCode is in it.
*/
export function akmRuntimeDir() {
return path.join(getDataDir(), "opencode-runtime");
}
/** The user's OpenCode database. */
export function opencodeDatabasePath(env = process.env) {
return databaseIn(opencodeDataDir(env));
}
/** Where akm's own runtime keeps its sessions: the `opencode/opencode.db` OpenCode makes under the runtime's `XDG_DATA_HOME`. */
export function akmOpencodeDatabasePath() {
return databaseIn(path.join(akmRuntimeDir(), "data", "opencode"));
}