MCPcopy Create free account
hub / github.com/apache/maka / buildLocalMemoryPromptBody

Function buildLocalMemoryPromptBody

packages/core/src/local-memory.ts:271–294  ·  view source on GitHub ↗
(
  input: string,
  context: LocalMemoryPromptContext = {},
)

Source from the content-addressed store, hash-verified

269}
270
271export 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
296export function appendManualLocalMemoryEntryDraft(
297 currentDraft: string,

Callers 3

readPromptProjectionMethod · 0.90

Calls 7

normalizeMetaValueFunction · 0.85
joinMethod · 0.80
redactSecretsFunction · 0.70
pushMethod · 0.65
testMethod · 0.65
trimMethod · 0.45

Tested by

no test coverage detected