MCPcopy Create free account
hub / github.com/echoVic/blade-code / enforceMemoryLimit

Method enforceMemoryLimit

src/context/storage/MemoryStore.ts:166–175  ·  view source on GitHub ↗

* 强制执行内存限制

()

Source from the content-addressed store, hash-verified

164 * 强制执行内存限制
165 */
166 private enforceMemoryLimit(): void {
167 if (!this.contextData) return;
168
169 const messages = this.contextData.layers.conversation.messages;
170 if (messages.length > this.maxSize) {
171 // 保留最近的消息,删除较旧的
172 const keepCount = Math.floor(this.maxSize * 0.8); // 保留80%的空间
173 this.contextData.layers.conversation.messages = messages.slice(-keepCount);
174 }
175 }
176
177 /**
178 * 估算内存使用量(以字符数为简单估算)

Callers 1

addMessageMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected