MCPcopy
hub / github.com/codeaashu/claude-code / buildMemoryLines

Function buildMemoryLines

src/memdir/memdir.ts:199–266  ·  view source on GitHub ↗
(
  displayName: string,
  memoryDir: string,
  extraGuidelines?: string[],
  skipIndex = false,
)

Source from the content-addressed store, hash-verified

197 * loadMemoryPrompt (system prompt, content injected via user context instead).
198 */
199export function buildMemoryLines(
200 displayName: string,
201 memoryDir: string,
202 extraGuidelines?: string[],
203 skipIndex = false,
204): string[] {
205 const howToSave = skipIndex
206 ? [
207 '## How to save memories',
208 '',
209 'Write each memory to its own file (e.g., `user_role.md`, `feedback_testing.md`) using this frontmatter format:',
210 '',
211 ...MEMORY_FRONTMATTER_EXAMPLE,
212 '',
213 '- Keep the name, description, and type fields in memory files up-to-date with the content',
214 '- Organize memory semantically by topic, not chronologically',
215 '- Update or remove memories that turn out to be wrong or outdated',
216 '- Do not write duplicate memories. First check if there is an existing memory you can update before writing a new one.',
217 ]
218 : [
219 '## How to save memories',
220 '',
221 'Saving a memory is a two-step process:',
222 '',
223 '**Step 1** — write the memory to its own file (e.g., `user_role.md`, `feedback_testing.md`) using this frontmatter format:',
224 '',
225 ...MEMORY_FRONTMATTER_EXAMPLE,
226 '',
227 `**Step 2** — add a pointer to that file in \`${ENTRYPOINT_NAME}\`. \`${ENTRYPOINT_NAME}\` is an index, not a memory — each entry should be one line, under ~150 characters: \`- [Title](file.md) — one-line hook\`. It has no frontmatter. Never write memory content directly into \`${ENTRYPOINT_NAME}\`.`,
228 '',
229 `- \`${ENTRYPOINT_NAME}\` is always loaded into your conversation context — lines after ${MAX_ENTRYPOINT_LINES} will be truncated, so keep the index concise`,
230 '- Keep the name, description, and type fields in memory files up-to-date with the content',
231 '- Organize memory semantically by topic, not chronologically',
232 '- Update or remove memories that turn out to be wrong or outdated',
233 '- Do not write duplicate memories. First check if there is an existing memory you can update before writing a new one.',
234 ]
235
236 const lines: string[] = [
237 `# ${displayName}`,
238 '',
239 `You have a persistent, file-based memory system at \`${memoryDir}\`. ${DIR_EXISTS_GUIDANCE}`,
240 '',
241 "You should build up this memory system over time so that future conversations can have a complete picture of who the user is, how they'd like to collaborate with you, what behaviors to avoid or repeat, and the context behind the work the user gives you.",
242 '',
243 'If the user explicitly asks you to remember something, save it immediately as whichever type fits best. If they ask you to forget something, find and remove the relevant entry.',
244 '',
245 ...TYPES_SECTION_INDIVIDUAL,
246 ...WHAT_NOT_TO_SAVE_SECTION,
247 '',
248 ...howToSave,
249 '',
250 ...WHEN_TO_ACCESS_SECTION,
251 '',
252 ...TRUSTING_RECALL_SECTION,
253 '',
254 '## Memory and other forms of persistence',
255 'Memory is one of several persistence mechanisms available to you as you assist the user in a given conversation. The distinction is often that memory can be recalled in future conversations and should not be used for persisting information that is only useful within the scope of the current conversation.',
256 '- When to use or update a plan instead of memory: If you are about to start a non-trivial implementation task and would like to reach alignment with the user on your approach you should use a Plan rather than saving this information to memory. Similarly, if you already have a plan within the conversation and you have changed your approach persist that change by updating the plan rather than saving a memory.',

Callers 2

buildMemoryPromptFunction · 0.85
loadMemoryPromptFunction · 0.85

Calls 2

pushMethod · 0.45

Tested by

no test coverage detected