MCPcopy Create free account
hub / github.com/Noumena-Network/code / applyDebugLogBudget

Function applyDebugLogBudget

src/utils/debug.ts:64–96  ·  view source on GitHub ↗
(
  path: string,
  content: string,
  existingBytes: number,
)

Source from the content-addressed store, hash-verified

62}
63
64function applyDebugLogBudget(
65 path: string,
66 content: string,
67 existingBytes: number,
68): string | null {
69 const maxBytes = getDebugLogMaxBytes()
70 const state = getDebugLogBudgetState(path)
71 if (!state.initialized) {
72 state.bytes = existingBytes
73 state.initialized = true
74 }
75 if (state.capped) {
76 return null
77 }
78 if (state.bytes + content.length <= maxBytes) {
79 state.bytes += content.length
80 return content
81 }
82
83 let preserved = ''
84 const lines = content.match(/[^\n]*\n|[^\n]+/g) ?? []
85 for (const line of lines) {
86 if (state.bytes + preserved.length + line.length > maxBytes) {
87 break
88 }
89 preserved += line
90 }
91
92 state.capped = true
93 const sentinel = `${new Date().toISOString()} [WARN] ${DEBUG_LOG_CAP_SENTINEL} maxBytes=${maxBytes} path=${path}\n`
94 state.bytes += preserved.length + sentinel.length
95 return preserved + sentinel
96}
97
98async function applyDebugLogBudgetAsync(
99 path: string,

Callers 2

applyDebugLogBudgetAsyncFunction · 0.85
applyDebugLogBudgetSyncFunction · 0.85

Calls 1

getDebugLogBudgetStateFunction · 0.85

Tested by

no test coverage detected