Returns Wolf directory path from config or environment for filesystem use.
import * as fs from "node:fs"
import * as path from "node:path"
import * as crypto from "node:crypto"
export function getWolfDir(directory: string): string {
return path.join(directory, ".wolf")
}
export function wolfDirExists(directory: string): boolean {
return fs.existsSync(getWolfDir(directory))
}
export function readJSON<T>(filePath: string, fallback: T): T {
try {
return JSON.parse(fs.readFileSync(filePath, "utf-8")) as T
} catch {
return fallback
}
}
export function writeJSON(filePath: string, data: unknown): void {
const dir = path.dirname(filePath)
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true })
const tmp = filePath + "." + crypto.randomBytes(4).toString("hex") + ".tmp"
try {
fs.writeFileSync(tmp, JSON.stringify(data, null, 2), "ut
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key