{"version":3,"file":"memoryFlushPrompt.mjs","sources":["../../../src/prompts/memoryFlushPrompt.ts"],"sourcesContent":["/**\n * Memory-flush prompt resolver.\n *\n * The raw prompt strings live in `src/memory/constants.ts` and contain a\n * single `{{MEMORY_PATHS_RUBRIC}}` placeholder. This module substitutes\n * the caller-scoped rubric (produced by `renderPathsRubric()` in\n * `src/memory/paths.ts`) into that placeholder at flush time, so:\n *\n *   - a collaborative agent with a real caller sees all 8 paths\n *   - an isolated/autonomous agent sees only the 4 agent-tier paths\n *     (user-tier rows are physically omitted from the rubric the LLM\n *      sees, so it cannot route writes there even by mistake)\n *\n * ## Why this lives in prompts/ and not memory/constants.ts\n *\n * The constants file is pure strings — no imports, no runtime work.\n * Injecting the rubric needs access to `renderPathsRubric()` which\n * needs `MemoryScope`, so the substitution has to happen one layer up.\n * Keeping the placeholder in constants and the substitution here means\n * tests of the raw prompt (no scope) and tests of the rendered prompt\n * (scope-aware) stay independent.\n */\nimport {\n  DEFAULT_MEMORY_FLUSH_PROMPT,\n  DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT,\n  FLUSH_PROMPT_RUBRIC_PLACEHOLDER,\n} from '@/memory/constants';\nimport { renderPathsRubric } from '@/memory/paths';\nimport type { MemoryScope } from '@/memory/types';\n\nexport { DEFAULT_MEMORY_FLUSH_PROMPT, DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT };\n\n/** Back-compat alias so existing callers keep working. */\nexport const MEMORY_FLUSH_SYSTEM_PROMPT = DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT;\n\n/** Minimum scope shape needed to render the rubric. */\nexport interface ResolveFlushPromptsOptions {\n  /**\n   * The scope the memory tools were built with. Only `userId` matters\n   * for rubric rendering — if absent, the user-tier paths are filtered\n   * out of the rubric the LLM sees.\n   */\n  scope: Pick<MemoryScope, 'userId'>;\n}\n\n/**\n * Result shape returned to `runMemoryFlush`. `prompt` goes in the\n * HumanMessage, `systemPrompt` goes in the SystemMessage. Both already\n * have the rubric substituted — the caller should pass them through\n * verbatim.\n */\nexport interface ResolvedFlushPrompts {\n  prompt: string;\n  systemPrompt: string;\n}\n\n/**\n * Substitutes the paths rubric into the raw prompts for a given scope.\n *\n * Idempotent (calling it twice on already-resolved strings is a no-op\n * because the placeholder will have been replaced already). Safe to\n * call per-flush; no caching needed — the string concat is microseconds.\n */\nexport function resolveFlushPrompts(\n  options: ResolveFlushPromptsOptions\n): ResolvedFlushPrompts {\n  const rubric = renderPathsRubric(options.scope);\n  return {\n    prompt: DEFAULT_MEMORY_FLUSH_PROMPT.replaceAll(\n      FLUSH_PROMPT_RUBRIC_PLACEHOLDER,\n      rubric\n    ),\n    systemPrompt: DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT.replaceAll(\n      FLUSH_PROMPT_RUBRIC_PLACEHOLDER,\n      rubric\n    ),\n  };\n}\n"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;AAqBG;AAWH;AACO,MAAM,0BAA0B,GAAG;AAuB1C;;;;;;AAMG;AACG,SAAU,mBAAmB,CACjC,OAAmC,EAAA;IAEnC,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC;IAC/C,OAAO;QACL,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAC5C,+BAA+B,EAC/B,MAAM,CACP;QACD,YAAY,EAAE,kCAAkC,CAAC,UAAU,CACzD,+BAA+B,EAC/B,MAAM,CACP;KACF;AACH;;;;"}