( agentType: string, scope: AgentMemoryScope, )
| 136 | * @param scope 'user' for ~/.claude/agent-memory/ or 'project' for .claude/agent-memory/ |
| 137 | */ |
| 138 | export function loadAgentMemoryPrompt( |
| 139 | agentType: string, |
| 140 | scope: AgentMemoryScope, |
| 141 | ): string { |
| 142 | let scopeNote: string |
| 143 | switch (scope) { |
| 144 | case 'user': |
| 145 | scopeNote = |
| 146 | '- Since this memory is user-scope, keep learnings general since they apply across all projects' |
| 147 | break |
| 148 | case 'project': |
| 149 | scopeNote = |
| 150 | '- Since this memory is project-scope and shared with your team via version control, tailor your memories to this project' |
| 151 | break |
| 152 | case 'local': |
| 153 | scopeNote = |
| 154 | '- Since this memory is local-scope (not checked into version control), tailor your memories to this project and machine' |
| 155 | break |
| 156 | } |
| 157 | |
| 158 | const memoryDir = getAgentMemoryDir(agentType, scope) |
| 159 | |
| 160 | // Fire-and-forget: this runs at agent-spawn time inside a sync |
| 161 | // getSystemPrompt() callback (called from React render in AgentDetail.tsx, |
| 162 | // so it cannot be async). The spawned agent won't try to Write until after |
| 163 | // a full API round-trip, by which time mkdir will have completed. Even if |
| 164 | // it hasn't, FileWriteTool does its own mkdir of the parent directory. |
| 165 | void ensureMemoryDirExists(memoryDir) |
| 166 | |
| 167 | const coworkExtraGuidelines = |
| 168 | process.env.CLAUDE_COWORK_MEMORY_EXTRA_GUIDELINES |
| 169 | return buildMemoryPrompt({ |
| 170 | displayName: 'Persistent Agent Memory', |
| 171 | memoryDir, |
| 172 | extraGuidelines: |
| 173 | coworkExtraGuidelines && coworkExtraGuidelines.trim().length > 0 |
| 174 | ? [scopeNote, coworkExtraGuidelines] |
| 175 | : [scopeNote], |
| 176 | }) |
| 177 | } |
| 178 |
no test coverage detected