MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / redactCtx

Function redactCtx

packages/agent-core/src/logging/formatter.ts:54–73  ·  view source on GitHub ↗
(ctx: LogContext)

Source from the content-addressed store, hash-verified

52}
53
54export function redactCtx(ctx: LogContext): LogContext {
55 const seen = new WeakSet<object>();
56 const walk = (value: unknown, depth: number): unknown => {
57 if (depth > REDACT_MAX_DEPTH) return '[REDACTED:depth]';
58 if (value === null || typeof value !== 'object') return value;
59 if (seen.has(value)) return '[REDACTED:cycle]';
60 seen.add(value);
61 if (Array.isArray(value)) {
62 return value.map((item) => walk(item, depth + 1));
63 }
64 const out: Record<string, unknown> = {};
65 for (const [key, raw] of Object.entries(value as Record<string, unknown>)) {
66 out[key] = REDACTED_KEYS.has(normalizeKey(key))
67 ? REDACTED
68 : walk(raw, depth + 1);
69 }
70 return out;
71 };
72 return walk(ctx, 0) as LogContext;
73}
74
75export interface FormatOptions {
76 readonly ansi?: boolean | undefined;

Callers 3

formatter.test.tsFile · 0.90
redactFunction · 0.90
formatEntryFunction · 0.85

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected