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

Function parseLocalMemoryMarkdownRaw

packages/core/src/local-memory.ts:621–711  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

619}
620
621function parseLocalMemoryMarkdownRaw(input: string): LocalMemoryRawParseResult {
622 const size = new TextEncoder().encode(input).byteLength;
623 if (size > LOCAL_MEMORY_MAX_BYTES) {
624 return {
625 entries: [],
626 activeEntries: [],
627 archivedEntries: [],
628 safeMode: true,
629 reason: 'oversize',
630 };
631 }
632 if (input.trim().length === 0) {
633 return {
634 entries: [],
635 activeEntries: [],
636 archivedEntries: [],
637 safeMode: false,
638 reason: 'empty',
639 };
640 }
641
642 const entries: LocalMemoryRawEntry[] = [];
643 const lines = input.split(/\r?\n/);
644 let current: { title: string; body: string[]; meta?: Record<string, string> } | null = null;
645
646 const flush = () => {
647 if (!current) return;
648 const content = current.body.join('\n').trim();
649 if (content.length > 0) {
650 const id = current.meta?.id || slugId(current.title);
651 const origin = normalizeOrigin(current.meta?.origin);
652 const source = normalizeSource(current.meta?.source, origin);
653 const status = normalizeEntryStatus(current.meta?.status, false);
654 const scope = normalizeScope(current.meta?.scope);
655 const createdAt = parseFiniteNumber(current.meta?.createdAt);
656 const updatedAt = parseFiniteNumber(current.meta?.updatedAt);
657 const proposedAt = parseFiniteNumber(current.meta?.proposedAt);
658 const confirmedAt = parseFiniteNumber(current.meta?.confirmedAt);
659 const archivedAt = parseFiniteNumber(current.meta?.archivedAt);
660 const rejectedAt = parseFiniteNumber(current.meta?.rejectedAt);
661 const decayTtlMs = parseFiniteNumber(current.meta?.decayTtlMs);
662 const approvedBy = current.meta?.approvedBy === 'user' ? 'user' : undefined;
663 const approvalSurface = normalizeApprovalSurface(current.meta?.approvalSurface);
664 entries.push({
665 id,
666 origin,
667 source,
668 status,
669 title: current.title,
670 content: content.slice(0, 500),
671 promptContent: content,
672 scope,
673 ...(current.meta?.sessionId ? { sessionId: current.meta.sessionId } : {}),
674 ...(current.meta?.proposalId ? { proposalId: current.meta.proposalId } : {}),
675 ...(current.meta?.sourceTurnId ? { sourceTurnId: current.meta.sourceTurnId } : {}),
676 ...(Number.isFinite(createdAt) ? { createdAt } : {}),
677 ...(Number.isFinite(updatedAt) ? { updatedAt } : {}),
678 ...(Number.isFinite(proposedAt) ? { proposedAt } : {}),

Callers 2

parseLocalMemoryMarkdownFunction · 0.85

Calls 5

parseMetaCommentFunction · 0.85
flushFunction · 0.70
execMethod · 0.65
pushMethod · 0.65
trimMethod · 0.45

Tested by

no test coverage detected