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

Function findLocalMemoryEntrySection

packages/core/src/local-memory.ts:744–785  ·  view source on GitHub ↗
(
  input: string,
  entryId: string,
)

Source from the content-addressed store, hash-verified

742}
743
744function findLocalMemoryEntrySection(
745 input: string,
746 entryId: string,
747): {
748 id: string;
749 headingLineIndex: number;
750 metaLineIndex?: number;
751 meta?: Record<string, string>;
752} | null {
753 const lines = input.split(/\r?\n/);
754 let current: {
755 title: string;
756 headingLineIndex: number;
757 metaLineIndex?: number;
758 meta?: Record<string, string>;
759 } | null = null;
760
761 const matchCurrent = () => {
762 if (!current) return null;
763 const id = current.meta?.id || slugId(current.title);
764 const proposalId = current.meta?.proposalId;
765 return id === entryId || proposalId === entryId ? { id, ...current } : null;
766 };
767
768 for (let index = 0; index < lines.length; index += 1) {
769 const line = lines[index] ?? '';
770 const heading = /^##\s+(.+?)\s*$/.exec(line);
771 if (heading) {
772 const matched = matchCurrent();
773 if (matched) return matched;
774 current = { title: heading[1] ?? '未命名记忆', headingLineIndex: index };
775 continue;
776 }
777 if (!current || current.meta) continue;
778 const meta = parseMetaComment(line);
779 if (meta) {
780 current.meta = meta;
781 current.metaLineIndex = index;
782 }
783 }
784 return matchCurrent();
785}
786
787function findLocalMemoryEntryFullSection(
788 input: string,

Callers 2

Calls 3

matchCurrentFunction · 0.85
parseMetaCommentFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected