Download src/logging/code-mode-diagnostic.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/logging/code-mode-diagnostic.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/logging/code-mode-diagnostic.ts
-
curl -L -o code-mode-diagnostic.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/logging/code-mode-diagnostic.ts
1.2 kB
| import { isTruthyEnvValue } from "../infra/env.js"; | |
| import { redactToolPayloadText } from "./redact.js"; | |
| import type { SubsystemLogger } from "./subsystem.js"; | |
| const MAX_NAMES = 24; | |
| const MAX_NAME_LENGTH = 80; | |
| type CodeModeDiagnosticFields = Record< | |
| string, | |
| boolean | number | string | readonly string[] | undefined | |
| >; | |
| export function isCodeModeDiagnosticEnabled(): boolean { | |
| return isTruthyEnvValue(process.env.OPENCLAW_DEBUG_CODE_MODE); | |
| } | |
| export function logCodeModeDiagnostic( | |
| log: Pick<SubsystemLogger, "info">, | |
| boundary: string, | |
| fields: CodeModeDiagnosticFields, | |
| ): void { | |
| if (!isCodeModeDiagnosticEnabled()) { | |
| return; | |
| } | |
| const bounded = Object.fromEntries( | |
| Object.entries(fields).map(([key, value]) => { | |
| if (Array.isArray(value)) { | |
| const names = [...new Set(value.map((name) => name.slice(0, MAX_NAME_LENGTH)))]; | |
| names.sort((left, right) => left.localeCompare(right)); | |
| return [key, names.slice(0, MAX_NAMES)]; | |
| } | |
| return [key, typeof value === "string" ? value.slice(0, MAX_NAME_LENGTH) : value]; | |
| }), | |
| ); | |
| log.info( | |
| redactToolPayloadText(`code-mode diagnostic ${JSON.stringify({ boundary, ...bounded })}`), | |
| ); | |
| } | |