{"version":3,"file":"constants.cjs","sources":["../../../src/memory/constants.ts"],"sourcesContent":["/**\n * Autonomous memory — shared constants.\n *\n * Single source of truth for defaults, limits, and magic strings used across\n * the memory store, tools, flush phase, and tests. Changing a value here\n * changes it everywhere — no hunting through files.\n */\n\n/** Default embedding provider when {@link process.env.MEMORY_EMBEDDINGS_PROVIDER} is unset. */\nexport const DEFAULT_MEMORY_PROVIDER = 'bedrock' as const;\n\n/** Default embedding model (Titan v2 — AWS-native, 6× cheaper than Cohere v4). */\nexport const DEFAULT_MEMORY_MODEL = 'amazon.titan-embed-text-v2:0';\n\n/** Default vector width (Titan v2 supports 256 / 512 / 1024). */\nexport const DEFAULT_MEMORY_DIMENSIONS = 1024;\n\n/** Default Postgres table name; can be overridden via env for dev/prod sharing. */\nexport const DEFAULT_MEMORY_TABLE = 'agent_memories';\n\n/** Default Postgres schema. */\nexport const DEFAULT_MEMORY_SCHEMA = 'public';\n\n/** Phase values used by the flush-phase gate. */\nexport const MEMORY_PHASE_NORMAL = 'normal';\nexport const MEMORY_PHASE_FLUSHING = 'memory_flushing';\n\n/**\n * Search defaults — aligned with upstream's upstream defaults.\n *\n * Sources:\n * - `upstream reference` → maxResults=6\n * - `upstream reference` → maxInjectedChars=4000\n *\n * Keeping these in lockstep with upstream means the mandatory-recall tool\n * description, budget clamps, and eval corpora line up with upstream's\n * tuning — we inherit their calibration instead of re-tuning from scratch.\n */\nexport const DEFAULT_MAX_SEARCH_RESULTS = 6;\nexport const DEFAULT_MIN_SCORE = 0.1;\nexport const DEFAULT_MAX_INJECTED_CHARS = 4000;\n\n/** Hybrid retrieval weights — 70% vector cosine, 30% BM25 / ts_rank text score. */\nexport const HYBRID_VECTOR_WEIGHT = 0.7;\nexport const HYBRID_TEXT_WEIGHT = 0.3;\n\n/**\n * Phase 2 rerank defaults — ported from upstream.\n *\n * Sources:\n * - `upstream reference` → lambda=0.7\n * - `upstream reference` → halfLifeDays=30\n *\n * Both features are opt-in (enabled=false by default) — the Phase 2\n * features are layered on top of hybrid search and don't change default\n * behavior for callers that upgrade in place.\n */\nexport const DEFAULT_MMR_ENABLED = false;\nexport const DEFAULT_MMR_LAMBDA = 0.7;\nexport const DEFAULT_TEMPORAL_DECAY_ENABLED = false;\nexport const DEFAULT_TEMPORAL_DECAY_HALF_LIFE_DAYS = 30;\nexport const DEFAULT_RECALL_TRACKING_ENABLED = false;\nexport const DEFAULT_CITATIONS_MODE = 'auto' as const;\n\n/**\n * Flush trigger margins (token counts) — aligned with upstream upstream.\n *\n * Sources:\n * - `upstream reference` → softThreshold=4000\n * - `upstream reference` → reserveFloor=20000\n */\nexport const DEFAULT_FLUSH_SOFT_THRESHOLD_TOKENS = 4000;\nexport const DEFAULT_FLUSH_RESERVE_FLOOR_TOKENS = 20000;\n\n/** Hard cap on append calls per flush phase — prevents runaway writes. */\nexport const DEFAULT_MAX_APPENDS_PER_FLUSH = 20;\n\n/**\n * Hard cap on agentic loop iterations inside {@link runMemoryFlush}.\n *\n * Each iteration = one model.invoke() followed by execution of any\n * `memory_append` tool_calls it emits. Mirrors upstream's flush-plan\n * loop cap; 8 is enough for ~2–3 reflections of batched notes while\n * protecting against runaway cycles if the model refuses to stop.\n */\nexport const DEFAULT_MAX_FLUSH_ITERATIONS = 8;\n\n/** Path prefix enforced on every append. Paths outside this are rejected. */\nexport const MEMORY_PATH_PREFIX = 'memory/';\n\n/** Tool names — kept as constants so server code + tests never drift. */\nexport const MEMORY_SEARCH_TOOL_NAME = 'memory_search';\nexport const MEMORY_GET_TOOL_NAME = 'memory_get';\nexport const MEMORY_APPEND_TOOL_NAME = 'memory_append';\n\n/**\n * Mandatory-recall description — the single most load-bearing line in the\n * whole memory system. Do not soften, shorten, or reword without an eval run.\n *\n * Ported VERBATIM from upstream `extensions/memory-core/src/tools.ts:186`.\n * The wiki/corpus clause is retained even though Phase 1 doesn't ship\n * compiled-wiki supplements — keeping the string identical means upstream's\n * eval corpora remain drop-in valid.\n */\nexport const MEMORY_SEARCH_DESCRIPTION =\n  'Mandatory recall step: semantically search MEMORY.md + memory/*.md ' +\n  '(and optional session transcripts) before answering questions about ' +\n  'prior work, decisions, dates, people, preferences, or todos. Optional ' +\n  '`corpus=wiki` or `corpus=all` also searches registered compiled-wiki ' +\n  'supplements. If response has disabled=true, memory retrieval is ' +\n  'unavailable and should be surfaced to the user.';\n\n/**\n * Ported VERBATIM from upstream `extensions/memory-core/src/tools.ts:322`.\n */\nexport const MEMORY_GET_DESCRIPTION =\n  'Safe snippet read from MEMORY.md or memory/*.md with optional from/lines; ' +\n  '`corpus=wiki` reads from registered compiled-wiki supplements. Use after ' +\n  'search to pull only the needed lines and keep context small.';\n\n/**\n * `memory_append` tool description.\n *\n * Phase 1 historically wrote to a single date-keyed file\n * (`memory/YYYY-MM-DD.md`), ported verbatim from upstream. That scheme\n * is now replaced by an 8-path canonical whitelist — see\n * {@link ./paths.MEMORY_ALL_PATHS}. The tool description no longer\n * names a specific file; the flush-turn prompt renders the full rubric\n * inline so the model sees every writable path at inference time.\n */\nexport const MEMORY_APPEND_DESCRIPTION =\n  \"Append a durable note to one of the agent's canonical memory documents. \" +\n  'The `path` argument MUST be one of the whitelisted paths listed in the ' +\n  'flush prompt rubric — unknown paths are rejected. Content is merged into ' +\n  'the existing row for that document via UPSERT, so the same document ' +\n  'accumulates across sessions.';\n\n/**\n * Reply token that signals the flush turn produced no user-visible output.\n * Ported VERBATIM from upstream `src/auto-reply/tokens.ts:4`.\n */\nexport const SILENT_REPLY_TOKEN = 'NO_REPLY';\n\n/**\n * Placeholder replaced at flush time with the rendered path-rubric for\n * the caller's scope. See `renderPathsRubric()` in `./paths.ts` and\n * `resolveFlushPrompts()` in `../prompts/memoryFlushPrompt.ts`.\n *\n * Kept as a unique sentinel so `replaceAll` is safe even if the rubric\n * content happens to contain regex metacharacters.\n */\nexport const FLUSH_PROMPT_RUBRIC_PLACEHOLDER = '{{MEMORY_PATHS_RUBRIC}}';\n\n/**\n * Memory-flush prompts — canonical-document model.\n *\n * Every durable memory routes into one of 8 stable canonical documents\n * (4 agent-tier + 4 user-tier). The rubric is injected at flush time so\n * the model reads the authoritative path list with descriptions, and for\n * isolated/autonomous agents the user-tier rows are transparently omitted\n * from the rubric — making \"user-tier writes require a scoped caller\" a\n * compile-time guarantee rather than a runtime check alone.\n *\n * Two-tier semantics the prompt enforces:\n *   - **agent/** — shared operational knowledge; every user of this agent\n *     benefits from rows written here. Do NOT put personal facts here.\n *   - **user/** — personalization for the specific caller only. Row is\n *     private to that user; other users never see it.\n */\nconst MEMORY_FLUSH_ROUTING_HINT =\n  'Route every note into exactly one of the canonical documents below by ' +\n  'picking the best match. Do NOT invent new paths; do NOT create date-keyed ' +\n  'files; unknown paths are rejected by the store.';\n\nconst MEMORY_FLUSH_TIER_HINT =\n  'Two tiers: `memory/agent/*` is SHARED operational knowledge visible to ' +\n  'every user of this agent — put successful patterns, pitfalls, domain ' +\n  'facts, and house-style there. `memory/user/*` is PRIVATE to the specific ' +\n  'caller — put their identity, preferences, projects, and references there. ' +\n  'Never put user-specific facts in an agent/* document.';\n\nconst MEMORY_FLUSH_READ_ONLY_HINT =\n  'Treat workspace bootstrap/reference files such as MEMORY.md, DREAMS.md, SOUL.md, TOOLS.md, and AGENTS.md as read-only during this flush; never overwrite, replace, or edit them.';\n\n/**\n * Learning hint — steers the flush turn to capture the things that\n * matter most for future turns: reusable patterns, tool failures\n * (so the same mistake is not repeated), explicit corrections, and\n * durable user-specific facts. Append-only via `memory_append`; one\n * note per lesson.\n */\nconst MEMORY_FLUSH_LEARNING_HINT =\n  'Capture durable lessons the agent (and future turns) should retain: ' +\n  '(a) successful task patterns and workflows → memory/agent/playbook.md; ' +\n  '(b) tool failures and schema mistakes → memory/agent/pitfalls.md; ' +\n  '(c) stable domain facts about the systems/APIs → memory/agent/domain.md; ' +\n  \"(d) this user's preferences, tone, and corrections → memory/user/preferences.md; \" +\n  \"(e) this user's identity and role → memory/user/profile.md. \" +\n  'Write one note per distinct lesson. Do not log conversation summaries ' +\n  'or anything derivable from the code or recent history.';\n\nconst MEMORY_FLUSH_RUBRIC_BLOCK =\n  'Canonical documents available for this turn (path — tag — description):\\n' +\n  FLUSH_PROMPT_RUBRIC_PLACEHOLDER;\n\nexport const DEFAULT_MEMORY_FLUSH_PROMPT = [\n  'Pre-compaction memory flush.',\n  MEMORY_FLUSH_ROUTING_HINT,\n  MEMORY_FLUSH_TIER_HINT,\n  MEMORY_FLUSH_READ_ONLY_HINT,\n  MEMORY_FLUSH_LEARNING_HINT,\n  'Call the `memory_append` tool for every note you want to persist, passing one of the whitelisted paths as the `path` argument. Do NOT describe what you are about to write; just call the tool.',\n  `If nothing worth storing, reply with exactly ${SILENT_REPLY_TOKEN}.`,\n  '',\n  MEMORY_FLUSH_RUBRIC_BLOCK,\n].join('\\n');\n\nexport const DEFAULT_MEMORY_FLUSH_SYSTEM_PROMPT = [\n  'Pre-compaction memory flush turn.',\n  'The session is near auto-compaction; capture durable memories to disk.',\n  MEMORY_FLUSH_ROUTING_HINT,\n  MEMORY_FLUSH_TIER_HINT,\n  MEMORY_FLUSH_READ_ONLY_HINT,\n  MEMORY_FLUSH_LEARNING_HINT,\n  'Use the `memory_append` tool for every durable note, with `path` set to one of the whitelisted canonical documents. Never claim you wrote a note without actually calling the tool.',\n  `If there is nothing worth storing, reply with exactly ${SILENT_REPLY_TOKEN}.`,\n  '',\n  MEMORY_FLUSH_RUBRIC_BLOCK,\n].join('\\n');\n"],"names":[],"mappings":";;AAAA;;;;;;AAMG;AAEH;AACO,MAAM,uBAAuB,GAAG;AAEvC;AACO,MAAM,oBAAoB,GAAG;AAEpC;AACO,MAAM,yBAAyB,GAAG;AAEzC;AACO,MAAM,oBAAoB,GAAG;AAEpC;AACO,MAAM,qBAAqB,GAAG;AAErC;AACO,MAAM,mBAAmB,GAAG;AAC5B,MAAM,qBAAqB,GAAG;AAErC;;;;;;;;;;AAUG;AACI,MAAM,0BAA0B,GAAG;AACnC,MAAM,iBAAiB,GAAG;AAC1B,MAAM,0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