UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

37 lines (36 loc) • 1.23 kB
import { r as resolveStateDir } from "../../state-dir-DiG0gXzD.mjs"; import "../../paths-DAcAg5aV.mjs"; import { t as formatErrorMessage } from "../../errors-BKzCeTYb.mjs"; import { n as appendRegularFile } from "../../fs-safe-BbWvmdVn.mjs"; import { t as createSubsystemLogger } from "../../subsystem-BHJiy01V.mjs"; import path from "node:path"; import fs from "node:fs/promises"; import os from "node:os"; //#region src/hooks/bundled/command-logger/handler.ts const log = createSubsystemLogger("command-logger"); const logCommand = async (e) => { if (e.type !== "command") return; try { const t = resolveStateDir(process.env, os.homedir); const n = path.join(t, "logs"); await fs.mkdir(n, { recursive: true }); const r = path.join(n, "commands.log"); const i = JSON.stringify({ timestamp: e.timestamp.toISOString(), action: e.action, sessionKey: e.sessionKey, senderId: e.context.senderId ?? "unknown", source: e.context.commandSource ?? "unknown" }) + "\n"; await appendRegularFile({ filePath: r, content: i, rejectSymlinkParents: true }); } catch (e) { const t = formatErrorMessage(e); log.error(`Failed to log command: ${t}`); } }; //#endregion export { logCommand as default };