|
1 | 1 | /** |
2 | 2 | * Builds and sanitizes bootstrap context inserted into embedded-agent sessions. |
3 | 3 | */ |
4 | | -import { createHash } from "node:crypto"; |
5 | 4 | import fs from "node:fs/promises"; |
6 | 5 | import path from "node:path"; |
7 | 6 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
@@ -118,13 +117,6 @@ type PolicyDigest = { |
118 | 117 | omittedLines: number; |
119 | 118 | }; |
120 | 119 |
|
121 | | -let lastAgentsPolicyDigestCache: |
122 | | - | { |
123 | | - key: string; |
124 | | - digest: PolicyDigest; |
125 | | - } |
126 | | - | undefined; |
127 | | - |
128 | 120 | export function resolveBootstrapMaxChars(cfg?: OpenClawConfig, agentId?: string | null): number { |
129 | 121 | const raw = |
130 | 122 | cfg && agentId |
@@ -183,25 +175,11 @@ function normalizePolicyDigestLine(line: string): string { |
183 | 175 | return `${truncateUtf16Safe(normalized, AGENTS_POLICY_DIGEST_MAX_LINE_CHARS - 1)}…`; |
184 | 176 | } |
185 | 177 |
|
186 | | -function agentsPolicyDigestCacheKey(content: string, budget: number): string { |
187 | | - return `${budget}:${content.length}:${createHash("sha256").update(content).digest("base64url")}`; |
188 | | -} |
189 | | - |
190 | | -function rememberAgentsPolicyDigest(key: string, digest: PolicyDigest): PolicyDigest { |
191 | | - lastAgentsPolicyDigestCache = { key, digest }; |
192 | | - return digest; |
193 | | -} |
194 | | - |
195 | 178 | function buildAgentsPolicyDigest(content: string, budget: number): PolicyDigest { |
196 | 179 | if (budget <= 0) { |
197 | 180 | return { text: "", omittedLines: 0 }; |
198 | 181 | } |
199 | 182 |
|
200 | | - const cacheKey = agentsPolicyDigestCacheKey(content, budget); |
201 | | - if (lastAgentsPolicyDigestCache?.key === cacheKey) { |
202 | | - return lastAgentsPolicyDigestCache.digest; |
203 | | - } |
204 | | - |
205 | 183 | const candidates = content |
206 | 184 | .split(/\r?\n/u) |
207 | 185 | .map((line, index) => ({ index, line: normalizePolicyDigestLine(line) })) |
@@ -234,10 +212,10 @@ function buildAgentsPolicyDigest(content: string, budget: number): PolicyDigest |
234 | 212 | .filter((candidate) => selected.has(candidate.index)) |
235 | 213 | .toSorted((a, b) => a.index - b.index) |
236 | 214 | .map((candidate) => candidate.line); |
237 | | - return rememberAgentsPolicyDigest(cacheKey, { |
| 215 | + return { |
238 | 216 | text: lines.join("\n"), |
239 | 217 | omittedLines: Math.max(0, candidates.length - lines.length), |
240 | | - }); |
| 218 | + }; |
241 | 219 | } |
242 | 220 |
|
243 | 221 | function trimAgentsBootstrapContent(content: string, maxChars: number): TrimBootstrapResult { |
|
0 commit comments