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

Function loadMemoryPrompt

src/memdir/memdir.ts:419–507  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

417 * Returns null when auto memory is disabled.
418 */
419export async function loadMemoryPrompt(): Promise<string | null> {
420 const autoEnabled = isAutoMemoryEnabled()
421
422 const skipIndex = getFeatureValue_CACHED_MAY_BE_STALE(
423 'tengu_moth_copse',
424 false,
425 )
426
427 // KAIROS daily-log mode takes precedence over TEAMMEM: the append-only
428 // log paradigm does not compose with team sync (which expects a shared
429 // MEMORY.md that both sides read + write). Gating on `autoEnabled` here
430 // means the !autoEnabled case falls through to the tengu_memdir_disabled
431 // telemetry block below, matching the non-KAIROS path.
432 if (feature('KAIROS') && autoEnabled && getKairosActive()) {
433 logMemoryDirCounts(getAutoMemPath(), {
434 memory_type:
435 'auto' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
436 })
437 return buildAssistantDailyLogPrompt(skipIndex)
438 }
439
440 // Cowork injects memory-policy text via env var; thread into all builders.
441 const coworkExtraGuidelines =
442 process.env.CLAUDE_COWORK_MEMORY_EXTRA_GUIDELINES
443 const extraGuidelines =
444 coworkExtraGuidelines && coworkExtraGuidelines.trim().length > 0
445 ? [coworkExtraGuidelines]
446 : undefined
447
448 if (feature('TEAMMEM')) {
449 if (teamMemPaths!.isTeamMemoryEnabled()) {
450 const autoDir = getAutoMemPath()
451 const teamDir = teamMemPaths!.getTeamMemPath()
452 // Harness guarantees these directories exist so the model can write
453 // without checking. The prompt text reflects this ("already exists").
454 // Only creating teamDir is sufficient: getTeamMemPath() is defined as
455 // join(getAutoMemPath(), 'team'), so recursive mkdir of the team dir
456 // creates the auto dir as a side effect. If the team dir ever moves
457 // out from under the auto dir, add a second ensureMemoryDirExists call
458 // for autoDir here.
459 await ensureMemoryDirExists(teamDir)
460 logMemoryDirCounts(autoDir, {
461 memory_type:
462 'auto' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
463 })
464 logMemoryDirCounts(teamDir, {
465 memory_type:
466 'team' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
467 })
468 return teamMemPrompts!.buildCombinedMemoryPrompt(
469 extraGuidelines,
470 skipIndex,
471 )
472 }
473 }
474
475 if (autoEnabled) {
476 const autoDir = getAutoMemPath()

Callers 2

submitMessageMethod · 0.85
getSystemPromptFunction · 0.85

Calls 11

isAutoMemoryEnabledFunction · 0.85
featureFunction · 0.85
getKairosActiveFunction · 0.85
logMemoryDirCountsFunction · 0.85
ensureMemoryDirExistsFunction · 0.85
buildMemoryLinesFunction · 0.85
logEventFunction · 0.85
isEnvTruthyFunction · 0.85
getInitialSettingsFunction · 0.85

Tested by

no test coverage detected