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