(
input: string,
context: LocalMemoryPromptContext = {},
)
| 269 | } |
| 270 | |
| 271 | export function buildLocalMemoryPromptBody( |
| 272 | input: string, |
| 273 | context: LocalMemoryPromptContext = {}, |
| 274 | ): string | undefined { |
| 275 | const parsed = parseLocalMemoryMarkdownRaw(input); |
| 276 | if (parsed.safeMode || parsed.activeEntries.length === 0) return undefined; |
| 277 | |
| 278 | const sessionId = normalizeMetaValue(context.sessionId ?? ''); |
| 279 | const visibleEntries = parsed.activeEntries.filter( |
| 280 | (entry) => entry.scope !== 'session' || (sessionId.length > 0 && entry.sessionId === sessionId), |
| 281 | ); |
| 282 | const blocks = visibleEntries.map((entry) => { |
| 283 | const lines = [`## ${entry.title}`]; |
| 284 | if (entry.tags.length > 0) lines.push(`Tags: ${entry.tags.join(', ')}`); |
| 285 | lines.push(entry.promptContent); |
| 286 | return redactSecrets(lines.join('\n')); |
| 287 | }); |
| 288 | const body = blocks.join('\n\n').trim(); |
| 289 | if (body.length === 0) return undefined; |
| 290 | if (body.length <= LOCAL_MEMORY_PROMPT_MAX_CHARS) return body; |
| 291 | const truncated = body.slice(0, LOCAL_MEMORY_PROMPT_MAX_CHARS); |
| 292 | const boundarySafe = /[\uD800-\uDBFF]$/.test(truncated) ? truncated.slice(0, -1) : truncated; |
| 293 | return `${boundarySafe.trimEnd()}\n\n${LOCAL_MEMORY_PROMPT_TRUNCATION_MARKER}`; |
| 294 | } |
| 295 | |
| 296 | export function appendManualLocalMemoryEntryDraft( |
| 297 | currentDraft: string, |
no test coverage detected