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

Function setLocalMemoryEntryStatusDraft

packages/core/src/local-memory.ts:426–468  ·  view source on GitHub ↗
(
  currentDraft: string,
  input: SetLocalMemoryEntryStatusInput,
)

Source from the content-addressed store, hash-verified

424}
425
426export function setLocalMemoryEntryStatusDraft(
427 currentDraft: string,
428 input: SetLocalMemoryEntryStatusInput,
429): SetLocalMemoryEntryStatusResult {
430 const id = input.id.trim();
431 if (!id || (input.status !== 'active' && input.status !== 'archived')) {
432 return { ok: false, reason: 'invalid_id' };
433 }
434
435 const section = findLocalMemoryEntrySection(currentDraft, id);
436 if (!section) return { ok: false, reason: 'not_found' };
437
438 const now =
439 Number.isFinite(input.now) && input.now !== undefined
440 ? Math.max(0, Math.floor(input.now))
441 : Date.now();
442 const lines = currentDraft.split(/\r?\n/);
443 const meta = {
444 ...(section.meta ?? {}),
445 id: section.id,
446 status: input.status,
447 updatedAt: String(now),
448 ...(input.status === 'archived' && input.recordLifecycleMetadata
449 ? { archivedAt: String(now) }
450 : {}),
451 ...(input.status === 'archived' && input.recordLifecycleMetadata && input.archiveReason
452 ? { archiveReason: normalizeMetaValue(input.archiveReason) }
453 : {}),
454 };
455 const metaLine = `<!-- maka-memory: ${serializeMetaComment(meta)} -->`;
456
457 if (section.metaLineIndex !== undefined) {
458 lines[section.metaLineIndex] = metaLine;
459 } else {
460 lines.splice(section.headingLineIndex + 1, 0, metaLine);
461 }
462
463 const draft = lines.join('\n');
464 if (new TextEncoder().encode(draft).byteLength > LOCAL_MEMORY_MAX_BYTES) {
465 return { ok: false, reason: 'oversize' };
466 }
467 return { ok: true, draft };
468}
469
470export function approveLocalMemoryProposalDraft(
471 memoryDraft: string,

Callers 3

#commitSemanticMethod · 0.90
updateMemoryEntryStatusFunction · 0.90

Calls 6

normalizeMetaValueFunction · 0.85
serializeMetaCommentFunction · 0.85
joinMethod · 0.80
nowMethod · 0.65
trimMethod · 0.45

Tested by

no test coverage detected