fix: unblock bundled plugin load
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { createRequire } from "node:module";
|
||||
import util from "node:util";
|
||||
|
||||
import { type ClawdbotConfig, loadConfig } from "../config/config.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { isVerbose } from "../globals.js";
|
||||
import { stripAnsi } from "../terminal/ansi.js";
|
||||
import { type LogLevel, normalizeLogLevel } from "./levels.js";
|
||||
@@ -14,6 +15,8 @@ type ConsoleSettings = {
|
||||
};
|
||||
export type ConsoleLoggerSettings = ConsoleSettings;
|
||||
|
||||
const requireConfig = createRequire(import.meta.url);
|
||||
|
||||
function normalizeConsoleLevel(level?: string): LogLevel {
|
||||
if (isVerbose()) return "debug";
|
||||
return normalizeLogLevel(level, "info");
|
||||
@@ -28,8 +31,19 @@ function normalizeConsoleStyle(style?: string): ConsoleStyle {
|
||||
}
|
||||
|
||||
function resolveConsoleSettings(): ConsoleSettings {
|
||||
const cfg: ClawdbotConfig["logging"] | undefined =
|
||||
(loggingState.overrideSettings as LoggerSettings | null) ?? loadConfig().logging;
|
||||
let cfg: ClawdbotConfig["logging"] | undefined;
|
||||
if (loggingState.overrideSettings) {
|
||||
cfg = loggingState.overrideSettings as LoggerSettings;
|
||||
} else {
|
||||
try {
|
||||
const loaded = requireConfig("../config/config.js") as {
|
||||
loadConfig?: () => ClawdbotConfig;
|
||||
};
|
||||
cfg = loaded.loadConfig?.().logging;
|
||||
} catch {
|
||||
cfg = undefined;
|
||||
}
|
||||
}
|
||||
const level = normalizeConsoleLevel(cfg?.consoleLevel);
|
||||
const style = normalizeConsoleStyle(cfg?.consoleStyle);
|
||||
return { level, style };
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { createRequire } from "node:module";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import { Logger as TsLogger } from "tslog";
|
||||
|
||||
import { type ClawdbotConfig, loadConfig } from "../config/config.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import type { ConsoleStyle } from "./console.js";
|
||||
import { type LogLevel, levelToMinLevel, normalizeLogLevel } from "./levels.js";
|
||||
import { loggingState } from "./state.js";
|
||||
@@ -17,6 +18,8 @@ const LOG_PREFIX = "clawdbot";
|
||||
const LOG_SUFFIX = ".log";
|
||||
const MAX_LOG_AGE_MS = 24 * 60 * 60 * 1000; // 24h
|
||||
|
||||
const requireConfig = createRequire(import.meta.url);
|
||||
|
||||
export type LoggerSettings = {
|
||||
level?: LogLevel;
|
||||
file?: string;
|
||||
@@ -33,8 +36,19 @@ type ResolvedSettings = {
|
||||
export type LoggerResolvedSettings = ResolvedSettings;
|
||||
|
||||
function resolveSettings(): ResolvedSettings {
|
||||
const cfg: ClawdbotConfig["logging"] | undefined =
|
||||
(loggingState.overrideSettings as LoggerSettings | null) ?? loadConfig().logging;
|
||||
let cfg: ClawdbotConfig["logging"] | undefined;
|
||||
if (loggingState.overrideSettings) {
|
||||
cfg = loggingState.overrideSettings as LoggerSettings;
|
||||
} else {
|
||||
try {
|
||||
const loaded = requireConfig("../config/config.js") as {
|
||||
loadConfig?: () => ClawdbotConfig;
|
||||
};
|
||||
cfg = loaded.loadConfig?.().logging;
|
||||
} catch {
|
||||
cfg = undefined;
|
||||
}
|
||||
}
|
||||
const level = normalizeLogLevel(cfg?.level, "info");
|
||||
const file = cfg?.file ?? defaultRollingPathForToday();
|
||||
return { level, file };
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
|
||||
const requireConfig = createRequire(import.meta.url);
|
||||
|
||||
export type RedactSensitiveMode = "off" | "tools";
|
||||
|
||||
@@ -93,7 +97,15 @@ function redactText(text: string, patterns: RegExp[]): string {
|
||||
}
|
||||
|
||||
function resolveConfigRedaction(): RedactOptions {
|
||||
const cfg = loadConfig().logging;
|
||||
let cfg: ClawdbotConfig["logging"] | undefined;
|
||||
try {
|
||||
const loaded = requireConfig("../config/config.js") as {
|
||||
loadConfig?: () => ClawdbotConfig;
|
||||
};
|
||||
cfg = loaded.loadConfig?.().logging;
|
||||
} catch {
|
||||
cfg = undefined;
|
||||
}
|
||||
return {
|
||||
mode: normalizeMode(cfg?.redactSensitive),
|
||||
patterns: cfg?.redactPatterns,
|
||||
|
||||
Reference in New Issue
Block a user